9

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
Tonechas
  • 13,398
  • 16
  • 46
  • 80
Pythoner
  • 5,265
  • 5
  • 33
  • 49

2 Answers2

17

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
Tonechas
  • 13,398
  • 16
  • 46
  • 80
13

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

marshall.ward
  • 6,758
  • 8
  • 35
  • 50