this post was submitted on 08 Dec 2023
622 points (96.4% liked)

Programmer Humor

32472 readers
735 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 12 points 11 months ago* (last edited 11 months ago) (5 children)

Python, checking in ...

return (a or b)

Parentheses aren't necessary, I just prefer them for readability.

See python documentation on boolean operators for reference. Short story is a or b is an expression that evaluates to a if a is "truthy" else b. "Falsy" is empty strings/containers, 0 and None.

[–] [email protected] 5 points 11 months ago (1 children)

There was PEP 505 to add a none-aware operator, but it lost support.

[–] [email protected] 1 points 11 months ago

That’s a shame, it would have been fitting in “modern” Python along with the walrus and static type system.

load more comments (3 replies)