pyhton基础知识——if语句

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
上一篇:leetcode-题13.Romain to Integer


下一篇:【动态规划】LCS最长公共子序列