Python Ternary Operator Example: Here, we are implementing a program that will read age of a person and check whether person is eligible for voting or not using ternary operator.
三元运算符用于内联条件表达式。它最适用于易于阅读的简单,简洁的操作。参数的顺序与许多其他语言(例如 C,Ruby,Java 等)不同,当不熟悉 Python 的惊人行为的人使用它时(可能会颠倒顺序),这可能会导致错误。 有些人觉得它笨拙,因为它与正常的思想流程相反(首先考虑条件然后考虑影响)。