您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
判断
缩进代替大括号。
冒号(:)后换号缩进。
if
test=100
if test>50:
print('OK')
print('test')

if-elif-else
test=50
if test>200:
print('200')
elif test<100:
print('100')
else:
print('100-200')

列表
test1=[123,456,789]
if 123 in test1:
print('OK')

字典
test2={'hello':123,'world':456}
if 'hello' in test2:
print('OK')

循环
while
数值
test=0 while test<10: print(test) test+=1

集合
test1=set(['hello','world']) while test1: test2=test1.pop() print(test2)

for
集合
test3=set(['hello','world']) for t in test3:#相当于foreach print(t)

列表
test4=[123,456,789] for i in range(3): print(test4[i])
test5=[123,456,789,34,5435,26,2362,262,26,5] for i in range(len(test5)): print(test5[i])

continue
test6=[11,12,13,14,15,16,17,18,19,20] for i in test6: if i%2==0: print(i) else: continue print(i)

break
test7=[12,13,14,15,16,17,18,19,20] for i in test7: if i%2==0: print(i) else: break print(i)

以上所述是小编给大家介绍的Python基础—判断和循环详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对亿速云网站的支持!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。