# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python之函数用法__str__()
#http://www.cnblogs.com/hongfei/p/3858256.html #__str__()
#说明:直接打印对象的实现方法 #案例
class Fruit:
'''Fruit类'''
def __str__(self): # 定义对象的字符串表示
return self.__doc__ if __name__ == "__main__":
fruit = Fruit()
print str(fruit) #调用内置函数str()触发__str__()方法,输出结果为:Fruit类
print fruit #直接输出对象fruit,返回__str__()方法的值,输出结果为:Fruit类 print Fruit() #Fruit类,直接打印对象的实现方法
print Fruit #__main__.Fruit
相关文章
- python中setup函数的用法_python学习之setUp函数和tearDown函数
- python标准库math中计算平方根的函数_16 Python 标准库之 math 模块 - Python 进阶应用教程...
- python中pow的意思_python中pow函数用法及功能说明
- python学习之函数返回值
- Python之函数的递归、匿名函数、内置函数
- python学习之--自定义函数:
- python中bool函数用法_在python中bool函数的取值方法
- python中content的用法_python中append函数用法讲解
- python中xticks函数_基于matplotlib xticks用法详解
- loc和iloc函数用法详解(Python)