o0牛魔王0o
2021-03-25 22:30
# Enter a code
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')
for x in (Student,object,Teacher):
if isinstance(t,x) == False:
continue
else:
print('T is {}'.format(x))
改成
print('T is {}'.format(t.name))
代码没错,里面运行不出来是因为py版本比较老,去pycharm就出来了
Python3 进阶教程(新版)
41910 学习 · 236 问题
相似问题