Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 969
Pythoner Avatar asked May 19 '16 01:05

Pythoner


2 Answers

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
like image 188
Tonechas Avatar answered Oct 11 '22 19:10

Tonechas


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

like image 35
marshall.ward Avatar answered Oct 11 '22 20:10

marshall.ward