詹惠儿

2018-12-07   阅读量: 596

Python编程 Python数据分析 数据分析师

python的is和is not

扫码加入数据分析学习群

在Python中用于确定值是否属于某个类或类型。它们通常用于确定某个变量包含的数据类型。
有不同的身份运营商,如

  1. 'is'运算符 -如果运算符任一侧的变量指向同一对象,则求值为true,否则求值为false
  2. # Python program to illustrate the use
  3. # of 'is' identity operator
  4. x = 5
  5. if (type(x) is int):
  6. print ("true")
  7. else:
  8. print ("false")

2. 'is not'运算符 -如果运算符两侧的变量指向同一对象,则求值为false,否则为true。

# Python program to illustrate the

# use of 'is not' identity operator

x = 5.2

if (type(x) is not int):

print ("true")

else:

print ("false")

添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 1 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子