Latest web development tutorials

Python pass 語句

Python pass是空語句,是為了保持程序結構的完整性。

pass 不做任何事情,一般用做佔位語句。

Python語言pass語句語法格式如下:

pass

實例:

#!/usr/bin/python
# -*- coding: UTF-8 -*- 

# 输出 Python 的每个字母
for letter in 'Python':
   if letter == 'h':
      pass
      print '这是 pass 块'
   print '当前字母 :', letter

print "Good bye!"

以上實例執行結果:

当前字母 : P
当前字母 : y
当前字母 : t
这是 pass 块
当前字母 : h
当前字母 : o
当前字母 : n
Good bye!