16.Python开发基础(运算符之身份运算符)


一、身份运算符说明

运算符

说明

is

判断两个标签是不是引用自一个对象

is not

判断两个标签是不是引用

二、身份运算符示例

# 定义变量并查看变量的值的类型
>>> name = "chenliang"
>>> type(name)


# is运算符举例
>>> type(name) is str  # 判断name变量的值的类型是str类型
True
>>> type(name) is int  # 判断name变量的值的类型不是int类型
False

# is not运算符举例
>>> type(name) is not int # 判断name变量的值的类型不是int类型
True
>>> type(name) is not str # 判断name变量的值的类型不是str类型
False