您的位置:首页 > 编程语言 > Python开发

Python isinstance 和 type,类型判断

2017-10-09 14:38 555 查看
'''
a=10
print(isinstance(a,int))  #判断类型
mystr="123213"
print(isinstance(a,str))
print(isinstance(mystr,str)) #判断类型

a=10
print(isinstance(a,(str,float))) #(str,int)两种类型其中之一
'''
class  father:
pass

class son(father):
pass

print(isinstance(father(),father))
print(isinstance(son(),father)) #子类属于父类, isinstance
print(type(father())==father)
print(type(son())==father) #type类型严格检查
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python