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

来源:3-3 Python判断类型

shalomg

2021-02-18 22:22

print(isinstance(t,object))

写回答 关注

4回答

  • 小谢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))

    不会报错啊

Python3 进阶教程(新版)

学习函数式、模块和面向对象编程,掌握Python高级程序设计

41910 学习 · 236 问题

查看课程

相似问题