管理平台接口文档,优化业务流程的灵魂之匙
238
2022-08-25
Python流程控制(Python流程控制语句有哪些)
Python流程控制
1、if条件选择
# coding:utf-8# Time:2022/6/28 20:57# Author:Yang Xiaopengnum = 23if num>2: print("dayu")if num<2: print("xiaoyu")## if elseif num>10: print("D")else: print("A")## if elif elseif num < 10: print("D")elif num < 20: print("C")elif num < 30: print("B")else: print("A")## if 嵌套if num > 10: if num>20: if num >30: print("A") else: print("B") else: print("C")else: print("D")
2、for循环
# coding:utf-8# Time:2022/6/28 20:57# Author:Yang Xiaopengfor i in (1,2,3,4,5,6,7,8): if i < 8: print(i,end="____") else: print(i)list1 = [1,2,3,4,5,6]for item in list1: if item / 2 == 1: print(item)for item in "asjhlafjhkllsadk": if item == 'k': print(item) else: print(item,end="_")
3、while循环
# coding:utf-8# Time:2022/6/28 20:57# Author:Yang Xiaopeng# 死循环"""while True: pass"""num = 1while num<10: print(num,end="_") num+=1
4、break 及 continue
break: 结束循环continue 退出本轮循环,继续下一轮循环
# coding:utf-8# Time:2022/6/28 20:57# Author:Yang Xiaopengnum = 0while num<10: num += 1 if num <=6: continue print(num, end="_")print("")num =0while num<10: num = num + 1 if num == 6: break print(num, end="_")
作者:99号程序员
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~