# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://5ydycm.blog.51cto.com/115934/157548/ #http://my.oschina.net/syc2013/blog/335842 #类的专有方法(__str__) #类实例字符串化函数 class Friend(): def __init__(self,name): self.name=name #输出结果:<__main__.Friend instance at 0x1d92a70> #返回的是存储地址 if __name__=="__main__": friend = Friend(‘xiaodeng‘) print friend #怎么打印出一个对象的有感内容? class Friend(): def __init__(self,name): self.name=name def __str__(self): return self.name if __name__=="__main__": friend = Friend(‘xiaodeng‘) print friend
时间: 2024-12-12 15:17:50