Python编程语言学习:判断变量是否为NONE或False的几种常见写法(if not用法教程)
Python编程语言学习:判断变量是否为NONE或False的几种常见写法(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')
赞 (0)