1.if-elif-else结构
>>> age=12 >>> if age < 4: ... price = 0 ... elif age < 18: ... price = 5 ... else: ... price = 10 ... >>> price 5
- 可省略else代码块
2.使用if判断列表是否为空
>>> str = [] >>> if str: ... a = 1 ... else: ... a = 0 ... >>> a 0
2024-01-02 11:47:10
>>> age=12 >>> if age < 4: ... price = 0 ... elif age < 18: ... price = 5 ... else: ... price = 10 ... >>> price 5
>>> str = [] >>> if str: ... a = 1 ... else: ... a = 0 ... >>> a 0