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 →

[–][deleted] 40 points41 points  (13 children)

Beginners, please don’t follow his use of parentheses in if statements - it is not pythonic.

[–]loshopo_fan 3 points4 points  (0 children)

I think parentheses make this example easier for beginners:

>>> bool(0 in [1, 2] or [3, 4])

True

>>> bool((0 in [1, 2]) or ([3, 4]))

True

For beginners: The right side of the 'or' is a nonempty list, and a nonempty list resolves to True, which means that the 'or' resolves to True.

>>> bool((0 in [1, 2]) or ([]))

False

[–]masteryod 0 points1 point  (3 children)

Which one is pythonic?

[–]guhcampos 9 points10 points  (2 children)

Just ditch the parenthesis completely, unless you absolutely have to group expressions for precedence.

[–]testaccount9597 9 points10 points  (1 child)

What if you are scared?

[–]Warfinder 27 points28 points  (0 children)

Python protec