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!

 

C/C++中写法:
if(true)
; // do nothing
else
{} // do nothing

Python中写法:
if true:
pass # do nothing
else:
print “do something.”

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
猜你喜欢
  • 2022-02-04
  • 2022-01-02
  • 2022-12-23
  • 2021-10-28
  • 2021-08-09
  • 2022-01-14
相关资源
相似解决方案