所有的for循环分支是否都可以用while改写
python3吧
全部回复
仅看楼主
level 2
梓555
楼主
python 所有的for循环分支是否都可以用while改写,可以举例吗
2020年06月30日 09点06分
1
level 11
雨巷纸伞-迷途
可以,【。。】表示一个缩进
------
for i in range(5):
。。代码块
----------等同于-------
i = 0
while i < 5:
。。代码块
。。i += 1
2020年06月30日 14点06分
3
梓555
那如果是for i in list:或是for i in str:这个如何用while代替
2020年07月01日 05点07分
画了个星星
可以
2020年07月03日 14点07分
ohmai
那所有的while循环都可以用for改写吗
2020年07月12日 08点07分
雨巷纸伞-迷途
@ohmai
也可以,但不建议
既然用了while循环那改for很麻烦
2020年07月12日 14点07分
level 11
雨巷纸伞-迷途
for i in list:
。。代码块
----------等同于-------
i = 0
while i < len(list):
。。代码块
。。【取值的话 list[i] 】
。。i += 1
2020年07月01日 07点07分
4
梓555
懂了,老哥厉害
2020年07月01日 09点07分
1