python之函数用法__str__()
# -*- 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之函数用法__str__()的更多相关文章
- python之函数用法setattr(),了解即可
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法setattr(),了解即可 #http://www.cnblogs.com/hong ...
- Python回调函数用法实例详解
本文实例讲述了Python回调函数用法.分享给大家供大家参考.具体分析如下: 一.百度百科上对回调函数的解释: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函 ...
- python之函数用法setdefault()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法setdefault() #D.get(k,d) #说明:k在D中,则返回 D[K], ...
- python之函数用法fromkeys()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法fromkeys() #fromkeys() #说明:用于创建一个新字典,以序列seq ...
- python之函数用法get()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法get() #http://www.runoob.com/python/att-dic ...
- python之函数用法capitalize()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法capitalize() #capitalize() #说明:将字符串的第一个字母变成 ...
- python之函数用法isupper()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法isupper() #http://www.runoob.com/python/att ...
- python之函数用法islower()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法islower() #http://www.runoob.com/python/att ...
- python之函数用法startswith()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法startswith() #http://www.runoob.com/python/ ...
随机推荐
- MVC扩展ModelBinder,通过继承DefaultModelBinder把表单数据封装成类作为action参数
把视图省.市.街道表单数据,封装成一个类,作为action参数.如下: action方法参数类型: namespace MvcApplication1.Models{ public class ...
- 使用EF Model First创建edmx模型,数据库有数据的情况下,如何同时更新模型和数据库
使用"EF Model First",我们可以很直观地在edmx文件中创建数据模型,并根据模型生成数据库,整个过程快速而高效.可当数据库中有了一定的数据量,同时,可能需要对模型中字 ...
- Arcgis10.5 python按属性分割图层,属性相同分为一个图层
# coding=utf-8 """ Source code for potential gp tool to create outputs based on attri ...
- ConcurrentDictionary AddOrUpdate
var sessionId = a.Session.SessionID.ToString(); userDic.AddOrUpdate( authUser.UserId, sessionId, (ke ...
- Oracle存储过程update受外键约束的主键值时完整性冲突解决方式
1.问题背景 尽管在数据库操作中我们并不提倡改动主键,可是确实在实际生活中有这种业务需求: 表A有主键KA,表B中声明了一个references A(KA)的外键约束.我们须要改动A中某条目KA的值而 ...
- java int类型转换成String , 不足10位 在前面补0
String.format("%010d", 25); 0代表前面要补的字符 10代表字符串长度 d表示参数为整数类型 String s = "Hello World!& ...
- Struts2 无后缀action请求
如果将Struts2的filter-mapping配置成 <filter-mapping> <filter-name>struts2</filter-name> & ...
- Android之判断当前网络状态
/** * 检测网络是否可用 * @return */ public boolean isNetworkConnected() { ConnectivityManager cm = (Connecti ...
- 基于libhid/libusb进行开发
操作环境:ubuntu,基于libhid/libusb进行开发 libusb介绍: libusb 设计了一系列的外部API 为应用程序所调用,通过这些API应用程序可以操作硬件,从libusb的源 ...
- 机器学习简史brief history of machine learning
BRIEF HISTORY OF MACHINE LEARNING My subjective ML timeline (click for larger) Since the initial sta ...