this post was submitted on 08 Dec 2023
0 points (NaN% liked)

Programmer Humor

31997 readers
794 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
[โ€“] stebo02@sopuli.xyz 0 points 9 months ago (1 children)

Python:

return a or b

i like it because it reads like a sentence so it somewhat makes sense

and you can make it more comprehensive if you want to:

return a if a is not None else b

[โ€“] Turun@feddit.de 0 points 9 months ago* (last edited 9 months ago)

This diverges from the OP code snippets if a has the value False.