0
Is there a PEP suggestion for the use of the ternary operator?
3 Réponses
+ 3
PEP8 does not specifically mention the ternary operator, but it contradicts with the principle that each statement should be written in a separate line.
https://www.python.org/dev/peps/pep-0008/#other-recommendations
- find "compound statements"
See also:
https://stackoverflow.com/questions/35070436/python-ternary-style-is-this-good-or-bad-style
+ 2
yeah as long as it only contains one if statement:
x = "Enough" if len(lst) > 5 else "Need more"
However, if it contains multiple if statements then that makes it hard to read and therefore should be avoided.