0

In Python what is the difference between these two tuples?

t = (1)

and

t = (1,)
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134
The Man
  • 385
  • 1
  • 3
  • 12
  • 1
    The first is not a tuple, that's just a single integer, grouped by parentheses (and since there is no other expression here the parentheses are ignored). It is the **comma** that makes something a tuple (except for the empty tuple `()`)`. Parentheses are optional unless the commas could be interpreted as part of other, surrounding syntax (such as a call). – Martijn Pieters Jun 07 '16 at 20:30
  • 1
    The first one is an integer, not a tuple. Tuples with 1 element **require** the comma. – AliciaBytes Jun 07 '16 at 20:30

0 Answers0