←back to thread

160 points leontrolski | 1 comments | | HN request time: 0s | source
Show context
cpburns2009 ◴[] No.41887804[source]
For all of the syntax features Python has been adding over the years, this would be a nice enhancement: making the "else None" optional in the ternary if-expression. E.g.,

    spam = eggs if bar
    # vs
    spam = eggs if bar else None
replies(3): >>41887917 #>>41887943 #>>41888372 #
TwentyPosts ◴[] No.41887943[source]
Do we really need more syntactic sugar? Frankly, I am still confused why Python is going for a separate syntax for if expressions instead of just making its regular ifs into expressions
replies(2): >>41887952 #>>41888104 #
1. cpfohl ◴[] No.41887952[source]
This is literally just a short tutorial helping people get into the cpython codebase. This feedback is off topic.

Related to your comment, though: Python has had this syntax for a VERY long time.