1. class Student:
    2. pass
    3. class Mystudent(Student):
    4. pass
    5. obj = Student()
    6. print(type(obj)) #<class '__main__.Student'>
    7. print(type(obj) == Student) # True type(obj)其实是查看obj是由哪个类实例化来的
    8. print(type(obj).__dict__ == Student.__dict__) # True
    9. print('type(Student):', type(Student)) #type(Student): <class 'type'>
    10. print('type(int.__bases__):', type(int.__bases__)) #type(int.__bases__): <class 'tuple'>
    11. print('type(Student.__bases__):', type(Student.__bases__)) #type(Student.__bases__): <class 'tuple'>
    12. print('type.__bases__:', type.__bases__) #type.__bases__: (<class 'object'>,)
    13. print('object.__bases__:', object.__bases__) #object.__bases__: ()
    14. print('type(object):', type(object)) #type(object): <class 'type'>

    如上可知,type的父类type.bases,是object,
    type(object)为type,可知,object是type的实例

    class type(name, bases, dict)
    type()函数传入三个参数name、bases、dict
    name:字符串类型,代表类名
    bases:元组类型,代表基类(父类),即需要继承的类对象
    dict:字典类型,将定义的类属性、类方法、实例方法等以键值对的形式建立映射关系

    1. def __init__(self, name):
    2. # 实例属性
    3. self.name = name
    4. # 类方法
    5. @classmethod
    6. def study(cls):
    7. pass
    8. # 静态方法
    9. @staticmethod
    10. def cal_student_num():
    11. pass
    12. # 使用type()函数定义类
    13. A = type(
    14. 'A',
    15. (object,),
    16. {
    17. 'role': 'student',
    18. '__init__': __init__,
    19. 'study': study,
    20. 'cal_student_num': cal_student_num
    21. })