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

为什么判断是否是object类型会报错?

print(isinstance(t,object))

提问者:shalomg 2021-02-18 22:22

个回答

  • 小谢0_0
    2021-08-27 13:50:25

    http://img.mukewang.com/61287d090001e0ca08140637.jpg
    建议检查一下自己的代码

  • 浮___雲
    2021-05-18 07:49:15

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


  • 慕斯卡6257248
    2021-02-25 14:01:11

    t=Person('a','a')是没错的 

  • 无用之用648
    2021-02-19 17:19:27

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

    不会报错啊