易百教程

81、如何在 Python 中编写条件表达式?

可以将以下单个语句用作条件表达式。 default_statment if Condition else another_statement,示例代码如下:

>>> no_of_days = 366
>>> is_leap_year = "Yes" if no_of_days == 366 else "No"\n>>> print(is_leap_year)
Yes