var = 1
while var == 1: # 该条件永远为true,循环将无限执行下去
num = input("Enter a number :") # 此时的num为string类型
print("You entered: ", num)
if num == str(0):
print("Good bye!")
break
循环使用 else 语句
在 python 中,while … else 在循环条件为 false 时执行 else 语句块:
#!/usr/bin/python
count = 0
while count < 5:
print count, " is less than 5"
count = count + 1
else:
print count, " is not less than 5"