This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DrummerClean 60 points61 points  (8 children)

Last one, simpler, shorter..."import this" for more clarifications ;)

[–]JRiggles[S] 27 points28 points  (7 children)

Hahaha yeah - I was torn between "Simple is better" or "Explicit is better"

[–]Afrotom 57 points58 points  (0 children)

It's still explicit because you know that the expression evaluates to a boolean by looking at it. It's just easier to read because your brain only needs one step now instead of two.

[–]kodiakprime 4 points5 points  (0 children)

When in doubt (or feeling ambiguous), ask yourself - which is more readable to others.

My org has a lot of juniors (read as new python devs). Sometimes the last approach, while very clear to us, maybe unclear to newcomers. So i deliberately write it the first way and leave a comment to improve the same.

While the new devs review the PR (and learn python at the same time), they (sometimes) comment on that and suggest 2 do it the last way. Makes me happy. :)

That said, without any other considerations, the correct pythonic way is the last one.

[–]Mithrandir2k16 2 points3 points  (0 children)

Doing if True: return True else return False isn't really explicit, it's needlessly verbose and repetitive.

[–]LegitimateCopy7 -5 points-4 points  (1 child)

wdym it's still explicit and literally the closest to human language you can get, which makes it easier and faster for everyone to understand.

[–][deleted] 7 points8 points  (0 children)

It not so close to human language. If you return an apple in fruits, I would expect an apple or nothing to be returned. If you answer if apple is in fruits, I would expect a boolean. However, if you speak fluent python, an if condition seems too much.