python學習——特殊方法__str__的用法

類中的str方法是在打印類的實例對象時,調用該方法,通常返回一個字符串。例如:python class Rectangle(): def __init__(self,a,b): self.a = a self.b = b def __str__(self): return 'this is a str' rect = Rectangl
相關文章
相關標籤/搜索