为什么判断是否是object类型会报错?
print(isinstance(t,object))
print(isinstance(t,object))
2021-02-18
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Student(Person):
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
class Teacher(Person):
def __init__(self, name, gender, course):
super(Teacher, self).__init__(name, gender)
self.course = course
p = Person('Tim', 'Male')
s = Student('Bob', 'Male', 88)
t = Teacher('Alice', 'Female', 'English')
print(isinstance(p, Person))
print(isinstance(p, Student))
print(isinstance(p, Teacher))
print(isinstance(p, object))
class Person:
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Student(Person):
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
class Teacher(Person):
def __init__(self, name, gender, subject):
super(Teacher, self).__init__(name, gender)
self.subject = subject
p = Person('Tim', 'male')
s = Student('Lily', 'Female', 88)
t = Teacher('Changyun', 'Female', 'English')
isinstance(t, Person)
isinstance(t, Teacher)
isinstance(t, Student)
print(isinstance(t, object))
不会报错啊
举报