python,關鍵詞pass

for letter in 'python':
    if letter == 'h':
        pass
        print " This is pass block"
    print "Current letter:", letter

print " Goodbye"

for letter in 'Patrick':
    if letter == 'r':
        pass
        print "This is pass block"
    print "Current letter:", letter
print "Goodbye"

It is used when a statement is required syntactically but you do not want any command or code to execute.
The pass statement is a null operation; nothing happens when it executes. The pass is also useful in places where your code will eventually go, but has not been written yet (e.g., in stubs for example):

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章