您当前的位置: 首页 >  Python
  • 0浏览

    0关注

    2393博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

一个处女座的程序猿 发布时间:2020-11-30 21:56:09 ,浏览量:0

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')

 

 

 

 

 

 

 

 

关注
打赏
1664196048
查看更多评论
立即登录/注册

微信扫码登录

0.0434s