課程
/后端開發
/Python
/初識Python
小白弱弱的問一下大神為什么這個編碼里面用whlie循環不對?
2017-03-01
源自:初識Python 5-8
正在回答
while只要你滿足條件 且條件不發生改變是會一直循環下去的
這里排列的遍歷顯然for循環是有優勢的
非要用的話:
s?=?set(['Adam',?'Lisa',?'Paul'])
L?=?['Adam',?'Lisa',?'Bart',?'Paul']
x=0
while x<3:
????if L[0] in?s:
????????s.remove(x)
? ? ? ? x=x+1
????else:
????????s.add(x)
print?s
while在重復的循環上合適,如何選取視情況而定
大俠你的圖呢?
s?=?set(['Adam',?'Lisa',?'Paul']) L?=?['Adam',?'Lisa',?'Bart',?'Paul'] for?x?in?L: ????if?x?in?s: ????????s.remove(x) ????else: ????????s.add(x) print?s
舉報
學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-03-01
while只要你滿足條件 且條件不發生改變是會一直循環下去的
這里排列的遍歷顯然for循環是有優勢的
非要用的話:
s?=?set(['Adam',?'Lisa',?'Paul'])
L?=?['Adam',?'Lisa',?'Bart',?'Paul']
x=0
while x<3:
????if L[0] in?s:
????????s.remove(x)
? ? ? ? x=x+1
????else:
????????s.add(x)
? ? ? ? x=x+1
print?s
while在重復的循環上合適,如何選取視情況而定
2017-03-01
大俠你的圖呢?
2017-03-01