在python编程中,类定义的代码如下:
class<classname>:<statement>类定义的特殊方法:
inituuuuuu构造函数,在生成对象时调用uuuudeluuuu析构函数,在释放对象时使用uuuuuurepruuuuuuuuprint,convert_uuuuiitem_uuuuuuuuuuuuu按索引赋值uuuuuuuuitem_uuuuuuuuuuu按索引获取值uuuuuuuulenuuuuuuuuuu获取长度uuuucmpuuuuuuuuuuuuuuuuuuuu比较运算uuuuuuuuuu调用uuuuuuuuuuuu函数调用uuuuuuuuuuuuuuuuu加法运算uuuuuuuuuuuuuuuuuuuuuu减法uuuuuuuuuuuuuuuuuuuuuu乘法uuuuuuuuuuuuuuudefinitionbasicattributename=“”age=0#definitionprivateattribute,不能在类uuuuuuuuuuweight=0之外直接访问#定义构造方法defuuuuuuuiit(self,n,a,w):姓名=n个自我年龄=aself.uuuweight=wdefspeak(self):打印(%s)正在讲话:我是%d岁“%(姓名,自我年龄))p=人(“汤姆”,10,30)p.说话()