Trailing comma produces a tuple, not the intended object
- comma
- tuple
- assignment
Compare the following two assignemnts
In [1]: x = 1
In [2]: print(x)
1
In [3]: x = 2,
In [4]: print(x)
(2,)
In the former, x
is assigned to be an integer 1
. In the latter, however, x
is assigned to be a tuple containing the integer 2
.