[英]List with square bracket and no brackets in Python
我想知道这两个都是列表。 在python中,这两个列表都是吗?
x = [1,2,3]
## and
y = 1,2,3
是y
列表?
不。第一个是列表,第二个是元组:
>>> x = [1,2,3]
>>> type(x)
<class 'list'>
>>> y = 1,2,3 # This is equivalent to doing: y = (1,2,3)
>>> type(y)
<class 'tuple'>
>>>
作为将来的说明,如果您想查看对象的类型,可以使用上面演示的内置type
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.