[英]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.