Skip to main content
15 events
when toggle format what by license comment
May 13, 2020 at 15:36 comment added SethMMorton @WalterTross The actual question was "Were I to change the python syntax so that the colon is no longer necessary, would anything break? Would that make some statements ambiguous or impossible?" While it is true that the motivation for asking the question was for block statements, the actual question can be summarized as "it should work for blocks without the colon, so am I missing something?" to which the answer is "yes, you are missing that inline blocks are allowed". Therefore, the question as asked was answered, regardless of the motivation behind asking.
May 13, 2020 at 14:28 comment added Walter Tross @SethMMorton the OP wrote “I keep forgetting the colon after the block initial statements in python” (which btw is what I do too), so this was the focus of his question, not all cases where the language requires a colon. I wrote this question in SO: stackoverflow.com/questions/60044102/…
May 12, 2020 at 16:47 comment added SethMMorton @WalterTross True, but the question asked if the colon could be removed safely and have no effect on the language. This answer proves it cannot, no need to try to give multiple examples when one falsifying case will do.
S May 11, 2020 at 18:18 history edited Glorfindel CC BY-SA 4.0
edited body
May 11, 2020 at 15:08 review Suggested edits
S May 11, 2020 at 18:18
Apr 5, 2019 at 22:19 comment added Walter Tross this answer only says that a colon is required when it is followed by a statement on the same line, it says nothing about the case when it is followed by a newline and increased indentation
Apr 11, 2018 at 15:02 comment added Michael Sandman Here is an encoding that let's you not use colons. Heed the warnings on this repo :) github.com/paradoxxxzero/nocolon
Jan 27, 2017 at 13:51 comment added Tomáš Zato Then this answers the question, without any doubt, because removing the comma from syntax would indeed break this. Thanks. I§m happy that the question served it's purpose and I learned something about python.
Jan 27, 2017 at 13:51 vote accept Tomáš Zato
Jan 27, 2017 at 13:29 comment added Lie Ryan @TomasZato: yes you can have any statements after the colon. It immediately terminates the block, so it's mainly useful when the block is a small one liner.
Jan 27, 2017 at 13:29 comment added RemcoGerlich Sure, just try it.
Jan 27, 2017 at 12:17 comment added Tomáš Zato Still a little confused. Is this allowed: if condition: print("Condition passed")\n allowed? The \n symbolises new line after the print statement.
Jan 27, 2017 at 12:14 comment added Phoshi It is permitted, but only with a linebreak after it.
Jan 27, 2017 at 12:00 comment added Tomáš Zato Wait, you can have a statement after the colon on the same line? I was pretty sure it's not allowed.
Jan 27, 2017 at 11:58 history answered Phoshi CC BY-SA 3.0