1.for循环
hello = "helloworld"
for i in hello:
print(i)
2.循环else
2.1 while循环 else
while 条件表达式:
代码块
else:
循环结束后执行的代码块
i = 1
while i <= 5:
print("媳妇,我错了")
i += 1
else:
print("媳妇原谅我了,我好开心")
2.for循环 else
hello = "HelloWorld"
for i in hello:
print(i)
else:
print("循环语句结束")
本文介绍了Python编程中for和while循环与else子句的结合使用。示例代码展示了如何在循环体内处理字符串以及循环结束后执行特定的代码块。

被折叠的 条评论
为什么被折叠?



