2018-12-07
阅读量:
780
python的is和is not
在Python中用于确定值是否属于某个类或类型。它们通常用于确定某个变量包含的数据类型。
有不同的身份运营商,如
- 'is'运算符 -如果运算符任一侧的变量指向同一对象,则求值为true,否则求值为false
- # Python program to illustrate the use
- # of 'is' identity operator
- x = 5
- if (type(x) is int):
- print ("true")
- else:
- 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)


暂无数据
推荐帖子
0条评论
0条评论
0条评论