问答详情
源自:3-3 Python判断类型

突发奇想,想真么写,但是为什么X打印不出来呢

# 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))

    


提问者:o0牛魔王0o 2021-03-25 22:30

个回答

  • weixin_慕盖茨3161772
    2021-07-05 22:00:00

    改成

    print('T is {}'.format(t.name))


  • qq_慕斯4138430
    2021-03-27 11:21:06

    代码没错,里面运行不出来是因为py版本比较老,去pycharm就出来了