热线电话:13121318867

登录
2018-12-07 阅读量: 780
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")

0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子