现在的位置: 首页 > 综合 > 正文

python difference of pass and continue

2013年10月10日 ⁄ 综合 ⁄ 共 650字 ⁄ 字号 评论关闭

Today I learned a little Python and figure out the difference of pass and continue

test code

mylist = ["zope","python","perl","linux"]
for technic in mylist:
        if technic == "perl":
               pass#this is pass
        else:
                print technic
        print "Hello World"

- - - - - - - - - - - - - - - - -

output :

zope
Hello World
python
Hello World
Hello World
linux
Hello World

- - - - - - - - - - - - - - - - -

mylist = ["zope","python","perl","linux"]
for technic in mylist:
        if technic == "perl":
              continue
        else:
                print technic
        print "Hello World"

- - - - - - - - - - -

zope
Hello World
python
Hello World
linux
Hello World

pass statement has print one more "hello world"
continue语句会忽略后面的语句,强制进入下一次循环。

pass不做任何事情。

抱歉!评论已关闭.