python and or 的高级用法
2016-05-03 15:16
525 查看
在github某开源代码里看到如下代码
def call(self, params = None, response = True, timeout = None):
res = *******
return response and res or None
于是特意尝试了下:
n=1235
print True and n
发现返回1235
123 and 12345 返回 12345
12345 and 123 返回 123
也就是说 and 如果为真的话总是返回第二个操作数
0 and 12345 返回 0
False and 12345 返回 False
def call(self, params = None, response = True, timeout = None):
res = *******
return response and res or None
于是特意尝试了下:
n=1235
print True and n
发现返回1235
123 and 12345 返回 12345
12345 and 123 返回 123
也就是说 and 如果为真的话总是返回第二个操作数
0 and 12345 返回 0
False and 12345 返回 False
相关文章推荐
- Python的yield协程机制实现生产者-消费者模式
- Python中super关键字的作用
- numpy上手笔记
- Python实现欧拉计划19题
- 125. Valid Palindrome [easy] (Python)
- Mac下配置Caffe的Python接口
- [python]连接两个List
- [Python]元组与列表的区别及内建用法
- python 参数 *
- Python中的除法 整除 非整除
- Python 异常处理 Python 基础教程 try..except
- Python list 数据类型:列表
- Python xlrd/xlwt对excel进行操作
- Python读取数据集并消除数据中的空行
- Python Dict all
- 我常用的 Python 调试工具
- [python] 优雅的操作字典
- python脚本管理日记文件
- Python datetime compare
- 使用 Python 进行稳定可靠的文件操作