Lab2013

Fight For A Good Future!

《笨办法学 Python》 学习笔记04 if-while-for

If
# Python expects you to indent something after you end a line

with a : (colon).

if people < cats:
    print "Too many cats! The world is doomed!"

if cars > people:
    print "We should take the cars."
elif cars < people:
    print "We should not take the cars."
else:
    print "We can't decide."

if people > buses:
    print "Alright, let's just take the buses."
else:
    print "Fine, let's stay home then."


For-loop

the_count = [1, 2, 3, 4, 5]
for number in the_count:
    print "This is count %d" % number

elements = []
for i in range(0, 6):
    print "Adding %d to the list." % i
    elements.append(i)
for i in elements:
    print "Element was: %d" % i



While-loop

# Make sure that you use while-loops sparingly. Usually a for-loop is better.



阅读更多
文章标签: python
个人分类: Python
想对作者说点什么? 我来说一句

笨办法python(中文第三版py3)

2017年09月01日 1.28MB 下载

笨办法Python

2018年02月28日 1019KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭