首页 > 其他 > 详细

The str method

时间:2014-10-02 21:02:43      阅读:326      评论:0      收藏:0      [点我收藏+]

__str__ is a special method name, like __init__, that is supposed to return a string representation of an object.

For example, here is a str method for Time objects. When you print an object, Python invokes the str method. when I write a new class, I almost always start by writing __init__, which makes it easier to instantiate objects, and __str__, which is almost always useful for debugging.

 def __str__(self):
        return (%.2d:%.2d:%.2d % (self.hour,self.minute,self.second))

bubuko.com,布布扣

 

from Thinking in Python

 

The str method

原文:http://www.cnblogs.com/ryansunyu/p/4004402.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!