我是靠谱客的博主 高大未来,这篇文章主要介绍Python编程语言学习:判断变量是否为NONE或False的几种常见写法(if not用法教程)判断变量是否为NONE或False的几种常见写法(if not用法教程),现在分享给大家,希望可以做个参考。
Python编程语言学习:判断变量是否为NONE或False的几种常见写法(if not用法教程)
目录
判断变量是否为NONE或False的几种常见写法(if not用法教程)
1、not用法
2、if not用法教程
判断变量是否为NONE或False的几种常见写法(if not用法教程)
1、not用法
#Python编程语言学习:判断变量是否为NONE或False的几种常见写法(if not用法教程)
import random
x_lists=[None,False,'',0,[],(),{}]
# x=random.sample(x_lists, 1)
x=random.choice(x_lists)
print(x)
if not x:
print('not x, x is False')
if x is None:
print('x is None')
2、if not用法教程
y=2020
if not y is None:
print('x is None')
if y is not None:
print('x is None')
最后
以上就是高大未来最近收集整理的关于Python编程语言学习:判断变量是否为NONE或False的几种常见写法(if not用法教程)判断变量是否为NONE或False的几种常见写法(if not用法教程)的全部内容,更多相关Python编程语言学习:判断变量是否为NONE或False的几种常见写法(if内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复