Python学习笔记(三) 控制语句
- if
s = input()
score = int(s)
if score >= 80:
print('A')
elif score < 80 and score >= 60:
print('B')
else:
print('C')
另外,if判断一个变量时,只要是非零、非空字符串、非空list就是True
- for
items = ['a', 'b', 'c']
for i in items:
print(i)
还可以用range()生成一个包含连续数字的list,range(x)的范围是0到x-1
sum = 0
for i in range(5):
sum = sum + i
print(sum)
结果是10
- while
sum = 0
i = 4
while i > 0:
sum = sum + i
i = i - 1
print(sum)
结果也是10
---> Python学习笔记目录
Categories
Tags
Jekyll(3)
Windows(1)
GitHub(4)
vs(4)
Portable(1)
hompage(1)
sitemap(1)
ruby(1)
gem(1)
qrcode(1)
jquery(1)
responsive(1)
Linux(6)
crontab(1)
sqlserver(4)
split(1)
backup(1)
js(1)
version(1)
csharp(2)
office(1)
com(1)
iis(1)
win8(1)
drag(1)
remote desktop(1)
Git GUI(1)
mail(1)
HTML(1)
table(1)
service(1)
32bit(1)
python(5)
pylesson(4)
volatile(1)
multithreading(1)
singleton(1)
webapi(2)
actionfilter(3)
filterprovider(1)