Python循环语句
import math
#测试循环
numbers = ["one","two","three"] #定义列表
for number in numbers:#遍历,测试for循环
print("number is : " + number)
#使用for循环和基本列表创建新列表
values = list(range(5)) #使用range创建list
for value in values:#遍历,测试嵌套for循环
for number in numbers:
if value == 3: #测试break
break
elif number == "two":#测试continue
continue
else:
print("value is {} number is {} ".format(value,number))
newValues = [val * val * math.pi for val in values] #使用for循环生成新list
for newVal in newValues:#遍历,测试for循环
print("circle is : " + str(newVal))
#while循环在上面已经介绍,下面只是一个例子
name = input("place input you name : ")
while name == "": #在条件满足时一直执行while内部的代码块,直到条件不满足时跳出循环,执行下面的代码
name = input("you input is null,place again input you name : ")
print("Hello " + name)
测试结果: