python pass (空操作)语句
来源:互联网 发布:IOS xml json 比较 编辑:程序博客网 时间:2024/05/07 14:47
转自:http://www.cnpythoner.com/post/286.html
pass语句通常什么都不做。它可以表示语句,但这个程序不需要的执行相应的动作。例如:
>>> while True:
... pass # Busy-wait for keyboard interrupt (Ctrl+C)
...
... pass # Busy-wait for keyboard interrupt (Ctrl+C)
...
这是常用的,用于创建最小的类:
>>> class MyEmptyClass:
... pass
...
... pass
...
另外,你可以只定义一个方法,方法里面的内容如果暂时没想好怎么写的话,可以用pass来代替,如果你留空,程序则会报错。
>>> def initlog(*args):
... pass # Remember to implement this!
...
... pass # Remember to implement this!
...
复制代码 代码如下:
#!/usr/bin/python
for letter in 'Python':
if letter == 'h':
pass
print 'This is pass block'
print 'Current Letter :', letter
print "Good bye!"
以上实例执行结果:
复制代码 代码如下:
Current Letter : P
Current Letter : y
Current Letter : t
This is pass block
Current Letter : h
Current Letter : o
Current Letter : n
Good bye!
0 0
- python pass (空操作)语句
- python pass (空操作)语句
- python pass 空语句 do nothing
- Python pass 语句
- Python pass语句
- Python pass 语句
- Python菜鸟--pass语句
- Python pass 语句
- Python pass 语句
- Python pass 语句
- Python pass 语句
- Python pass 语句
- Python pass 语句
- Python pass 语句
- python中pass语句
- Python pass 语句
- 【Python】pass 语句的用法
- python中pass语句学习
- POJ 2947-Widget Factory(高斯消元解同余方程式)
- 【LeetCode】19 Remove Nth Node From End of List (c++实现)
- Andorid 网络状态改变监听不到问题的解决
- 【LeetCode】20 Valid Parentheses (c++实现)
- scrollview 嵌套 viewpager 滑动冲突的解决办法
- python pass (空操作)语句
- 实列3_1
- 新建jenkins-plugin
- UIView frame, bounds and center
- 将List里面的User对象转化为json数据格式
- Null value was assigned to a property of primitive type setter of
- 内存管理笔记(分页,分段,逻辑地址,物理地址与地址转换方式)
- iOS地理定位
- POJ 2253