shalomg
2021-02-18 22:22
print(isinstance(t,object))
建议检查一下自己的代码
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))
t=Person('a','a')是没错的
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))
不会报错啊
Python3 进阶教程(新版)
41910 学习 · 236 问题
相似问题