目录
类对象
class 类名:
实际上, 当解释器执行class语句时, 就会创建一个类对象;
# 测试类对象的生成
class Student:
pass #空语句 ,解释器执行到这里,就创建了一个类对象, <class 'type'>
print(type(Student))
print(id(Student))
Stu2 = Student #它就是一个类对象
s1 = Stu2()
print(s1)
'''
我们可以看到实际上生成了一个变量名就是类名"Student"的对象,我们通过赋值给新变量Stu2,
也能实现相关的调用, 说明, 确实创建了"类对象"
注意: pass 为空语句, 就是表示什么都不做, 只是作为占位符存在, 当你写代码时, 遇到暂时不知
道方法或者类中加入什么时, 可以先用pass占位, 后期再补上
'''
输出:
D:\wwwroot\pyiteam\venv\Scripts\python.exe D:/wwwroot/pyiteam/mypro_obj/mypy02.py
<class 'type'>
57533400
<__main__.Student object at 0x036DC148>
Process finished with exit code 0