流程控制
- 顺序结构
- 选择结构,if
- 循环结构,for
顺序结构
# 顺序结构
'''去上学一共分为几步'''
print('----------程序开始---------------')
print('1、起床')
print('2、吃早饭')
print('3、步行去学校')
print('----------程序结束---------------')
对象的布尔值
Python一切皆对象,所有对象都有一个布尔值
获取对象的布尔值:使用内置函数bool()
以下对象的布尔值为False
- False
- 数值0
- None
- 空字符串
- 空列表
- 空元组
- 空字典
- 空集合
# 对象的布尔值
print('----------以下对象的布尔值为False---------------')
print(bool(False)) # False
print(bool(0)) # False
print(bool(0.0)) # False
print(bool(None)) # False
print(bool('')) # False
print(bool("")) # False
print(bool([])) # False,空列表
print(bool(list())) # False,空列表
print(bool(())) # False,空元组
print(bool(tuple())) # False,空元组
print(bool({})) # False,空字典
print(bool(dict())) # False,空字典
print(bool(set())) # False,空集合print('----------其他对象的布尔值为True---------------')
print(bool(10)) # True
print(bool('hello')) # True
print(bool(True)) # True