流程控制
程序执行流程
程序执行有三种:顺序执行,分支执行,循环执行。
顺序执行
从上而下,顺序的执行代码。
分支执行
根据条件判断,决定执行代码的分支
循环执行
根据条件判断,让指定的代码重复执行。
条件语句(if语句)
if 条件:
条件成立时,要做的事情
#if 条件
if 1 > 2:
print('bxg')
print(10)
10
#if else条件
if 1 > 2:
print('itcast')
else:
print('itheima')
itheima
#if elif else
if 1 > 2:
print('itcast')
elif 1 > 3:
print('bxg')
else:
print('itheima')
itheima
输入函数input(’请输入‘)
age = input('10')
#in 和 not in 条件判断
str = 'itheima'
print('it' in str)
True
#in 和 not in 条件判断
str = 'itheima'
#注意字符串有连续性
print('its' in str)
False
#列表
names = ['itcast','itheima','bxg']
print('itheima' in names)
True
#列表
names = ['itcast','itheima','bxg']
print('itheima' not in names)
False
#集合
names = {'itcast','itheima','bxg'}
print('itheima' not in names)
print('itheima' in names)
False
True
#元祖
names = ('itcast','itheima','bxg')
print('itheima' not in names)
False
#字典
d = {'name':'jinyuan','age':19}
#判断的是键值 Value
print('name' in d)
True