2018-11-19
阅读量:
721
Python里的for和while
可以用 if 语句来执行一种有条件的行动:
if 1 > 2:
message = "if only 1 were greater than two..."
elif 1 > 3:
message = "elif stands for 'else if'"
else:
message = "when all else fails use else (if you want to)"
也可以在一行语句中使用 if-then-else,我们有时候需要这么做:
parity = "even" if x % 2 == 0 else "odd"
Python 也有 while 循环:
x = 0
while x < 10:
print x, "is less than 10"
x += 1
尽管我们更常用 for 和 in:
for x in range(10):
print x, "is less than 10"






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论