python3+文件路径 回车
第一种:
print(111) if True: print(666) print(777) 和if无关系 都会打印
结果:111 666 777
第二种: if 4>3: print(666) else: print(777) 二选一
多选: num=input(‘请输入您猜的数字:‘) if num==‘1‘: print(‘ooo‘) elif num==‘2‘: print(‘kkkk‘) elif num==‘3‘: print(‘lllll‘) else: print(‘错了‘) 只要满足一个就不再往下执行
嵌套if: name=input(‘请输入名字:‘) age=input(‘请输入年龄:‘) if name == ‘小二‘ if age==‘18‘ print(666) else:
print(333) else:
print(‘错了‘)
while True: print(‘我们不一样‘) print(‘在人间‘)
while True: print(‘我们不一样‘) print(‘在人间‘) print(‘痒‘) print(‘222‘)
1-100输出
1 count=1 2 flag=True 3 while flag: 4 print(count) 5 count=count+1 6 if count>100: 7 flag=False
1-100的和:
1 count=1 2 num=0 3 while count<=100: 4 print(count) 5 num=num+count 6 count=count+1 7 print(num)
break用法:
1 count=1 2 while True: 3 print(count) 4 count=count+1 5 if count>100: 6 break
continue用法:
1 count=1
2 while count<=100:
3 print(count) 4 continue 5 count=count+1 6 print(num)
原文:https://www.cnblogs.com/qd1228/p/12319132.html