# coding=utf-8
class Family(object):
def __init__(self, name):
self.name = name
def call_name(self):
return self.name
if __name__ == "__main__":
a = Family("Tom").call_name()
b = Family("Tom").call_name()
c = Family("Jerry")
d = Family("Jerry")
# print a is b # 判断a 对象是b
# print a == b # 判断a 的值与b值相等
# print c is d
# print c == d
class A():
pass
class B(A):
pass
print isinstance(A(), A) # isinstance(object,classinfo)
print isinstance(B(),A)
a =1
b ='string'
c=(1,2)
print isinstance(a, int)
print isinstance(b, str)
print isinstance(c,(int,str,list,tuple))
"""isinstance() 与 type() 区别:
type() 不会认为子类是一种父类类型,不考虑继承关系。
isinstance() 会认为子类是一种父类类型,考虑继承关系。
如果要判断两个类型是否相同推荐使用 isinstance()
"""
isinstance,is 和==
最新推荐文章于 2024-07-08 15:55:46 发布