[python]Python 中 if not 用法
2023-02-18 15:41:17 时间
在python 判断语句中 None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于 False
not None == not False == not '' == not 0 == not [] == not {} == not ()
需要注意的是'0'这个进行判断返回的是true
def test(val): if not val: print 'not' else: print 'yes' test(0) test(None) test('0') if not 0: print 1111
返回
not not yes 1111
相关文章
- 5种Python使用定时调度任务的方式
- 教你用Python 编写 Hadoop MapReduce 程序
- [Python] for in单行循环生成dict
- [Python]reduce() 函数
- [Python]Python日期格式和字符串格式相互转换
- [Python]Python中使用正则表达式匹配
- [Python]Python 列表(List)
- [Python]python中assert和isinstance的用法
- [python]Python 中 if not 用法
- [python]Python 字典(Dictionary) update()方法
- [python]python中的一些包以及他们的基本用处和安装
- [python]ubuntu下的python2和python3
- [Python] 关于__init__.py
- [Python]安装和运行flask框架
- 在PyQt中构建 Python 菜单栏、菜单和工具栏
- 结合scipy.linalg在Python中使用线性系统
- [Python] 函数基本
- [Python] 使用dict和set
- [Python] Python基础字符串
- Python入门:ChainMap 有效管理多个上下文