TP147爱上Python(15)_定制类-----计算机学习实战.pptx

TP147爱上Python(15)_定制类-----计算机学习实战.pptx

爱上python (15)定制类;outline;什么是特殊方法;什么是特殊方法;Python如何把任意变量变成str;Python如何把任意变量变成str;Python的特殊方法;Python定义的特殊方法(部分);正确实现特殊方法;Python中 __str__和__repr__;__str__;__str__;__repr__;__str__和__repr__的区别;class Printer(object): def __init__(self,val): self.val = val def __str__(self): return str(self.val) objs = [Printer(2),Printer(3)] for x in objs: print (x) print (objs);__str__和__repr__的区别;class Person(object): def __init__(self, name, gender): self.name = name self.gender = gender class Student(Person): def __init__(self, name, gender, score): su

文档评论(0)

1亿VIP精品文档

相关文档