![](https://img2022.cnblogs.com/blog/1644491/202209/1644491-20220917201257089-247937956.png)
class Student: def __init__(self,name,age): self.name=name self.age=age def __str__(self): #object中有__str__()方法,用于对于 ‘对象的描述’ return '我的名字是{0},今年{1}岁'.format(self.name,self.age) stu=Student('张三',20) print(dir(stu)) #查看指定对象所有属性 print(stu) #默会调用__str__()这样的方法 print(type(stu))