Skip to main content

Command Palette

Search for a command to run...

Trailing commas in python

Published
โ€ข1 min readโ€ขView as Markdown

This has tripped me off way more than I would like. For those of you who don't know adding a comma makes a variable into tuple (Yes its not the C bracket)

foo = 1,
print(type(foo))

It prints:

<class 'tuple'>
45 views
S

It's always good to know about the different notation types: infix, postfix and prefix. Then, it's good to know how and when your language of choice decides to enforce them! Extending your example in 3.6 at the REPL confuses me more!

>>> foo = 1,
>>> print(type(foo))
<class 'tuple'>
>>> print(type(1,))
<class 'int'>
H

I understand infix, prefix and postfix though I dont know what exactly python does. And BTW i tried both. And it confused me more too. I will add this too ๐Ÿ˜๐Ÿ˜๐Ÿ˜