What's the difference between (1,) and (1) in python [duplicate]

三世轮回 提交于 2019-12-01 15:02:34

问题


As stated in the title, I found that (1) and (1,) are different. But what's the difference of them?

In[39]: (1) == (1,)
Out[39]: False

回答1:


The comma makes it a tuple. (1) is just the same as 1 wrapped in delimiters.




回答2:


Try this to convince yourself:

>>> type((1))
<type 'int'>
>>> type((1,))
<type 'tuple'>

The following identity checks may provide you with further insight into the differences:

>>> (1) is 1
True
>>> (1,) is 1
False


来源:https://stackoverflow.com/questions/37312512/whats-the-difference-between-1-and-1-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!