分享

Python编程语言学习:判断变量是否为NONE或False的几种常见写法(if not用法教程)

 处女座的程序猿 2021-09-28

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

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多