python 2 流程控制
2023-02-27 16:13 作者:戎碼關(guān)山 | 我要投稿
除了編程語(yǔ)言中常見的while和for循環(huán),python中還有一個(gè)獨(dú)特的while-else循環(huán)
#如果帶有else,則在while語(yǔ)句正常結(jié)束后執(zhí)行else;如果while被break破壞中止,則不執(zhí)行else
input_name = input("input your name here: ")
name_list = []
while input_name != 'q':
? ?name_list.append(input_name)
? ?input_name = input("input your name here: ")
else:
? ?print(name_list)
? ?print('Done!')
#容器和迭代器 list set dict tuple str
i = range(0,10,2)
print(list(i))
i = iter("123456")
print(next(i))
print(next(i))
標(biāo)簽: