Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
making : optional
#1
is there any case where a compound statement (if, while, for, try, with) can be made without ending with a : character? i cannot find any in the Python Language Reference. i am thinking that code with a missing : character could still be accepted as valid and be correctly understood as intended. perhaps this could be shown by a script that adds the missing : characters.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
https://docs.python.org/3/faq/design.htm...statements Wrote:Why are colons required for the if/while/def/class statements?
The colon is required primarily to enhance readability (one of the results of the experimental ABC language). Consider this:

if a == b
    print(a)
versus
if a == b:
    print(a)
Notice how the second one is slightly easier to read. Notice further how a colon sets off the example in this FAQ answer; it’s a standard usage in English.

Another minor reason is that the colon makes it easier for editors with syntax highlighting; they can look for colons to decide when indentation needs to be increased instead of having to do a more elaborate parsing of the program text.
Gribouillis likes this post
Reply
#3
I'm not sure it can always be done, consider the following statement
if a: - x >> spam + y
if you remove the colon it becomes
if a - x >> spam + y
where is the end of the if statement? It could mean
if a - x >> spam: + y
Also what is at stake? Would Python be any better without these colon characters? As I told you, i find much more interesting to remove the dot operator, and I already have a working system that does it at adddot
Reply
#4
ok, that's a case where the : has meaning and is needed. but if someone codes the hard to read:
if a == b
    print(a)
in some language fork that let the line separation imply the meaning, why not let : also do that (without restarting the indentation parsing at that point in the middle of the line)? iow, i'm not saying to remove the requirement of : unless it ends the line (not counting comments).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  making : optional Skaperen 3 2,291 Apr-06-2021, 06:23 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020