(1)*3 # 3 # 单个元素,忽略圆括号,不被视为tuple # 圆括号内无元素或含有多于一个元素,被视为tuple
[1]*3 # [1, 1, 1] # 方括号内无论有多少个元素(包括空列表),均被视为列表 # 以列表为单位重复3次,而不是列表内元素为单位重复3次,后者需要np.repeat,参考:https://blog.51cto.com/u_16055028/6189970
(1,1)*3 # (1, 1, 1, 1, 1, 1) # 多个元素,tuple类似list(参考:tuple与list的区别)
[1,1]*3 # [1, 1, 1, 1, 1, 1]
(1)**3 # 3
# [1]**3 # TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' # tuple和列表无法求幂(**操作符或pow函数)
# (1,1)**3 # TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'int'
# [1,1]**3 # TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
# (None)*3 # TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' # None无法进行运算
[None]*3 # [None, None, None]
(np.nan)*3 # nan
(np.nan, None)*3 # (nan, None, nan, None, nan, None)
总结
单个元素,忽略圆括号,不被视为tuple
圆括号内无元素或含有多于一个元素,被视为tuple
方括号内无论有多少个元素(包括空列表),均被视为列表
tuple和列表无法求幂(**操作符或pow函数)
None无法进行运算
以列表为单位重复3次,而不是列表内元素为单位重复3次,后者需要np.repeat,参考:https://blog.51cto.com/u_16055028/6189970