top | item 47077605

(no title)

ameliaquining | 10 days ago

Python doesn't have automatic semicolon insertion.

discuss

order

gingerBill|7 days ago

Yes it does. You can even type `;` anywhere too, go an try it.

Because of how good the rules are for Python's needs, most people never know that semicolons even exist in Python.

ameliaquining|7 days ago

This isn't quite right. Go and JavaScript use semicolons pervasively throughout their formal grammars, and mostly don't use newlines; then, on top of that, they have special rules that allow the semicolons to be omitted in many cases depending on newline placement. Python uses newlines pervasively throughout its formal grammar, and only allows semicolons to be used in a couple specific places (at the end of a simple statement or to separate multiple simple statements on a single line).

The two systems have in common that you can either include or omit a semicolon when you've got a simple statement on its own line, but under the hood they're different; the missing semicolon at the end of a line in idiomatic Python is not "automatically inserted by the parser", it is simply not needed at all. There are also behavioral differences; for example, in Go and JavaScript a semicolon on a line by itself is legal and does nothing, while in Python it's a syntax error.

1718627440|7 days ago

Python actually has optional semicolons.