在python语言里,__str__一般是格式是这样的。

class A:

def __str__(self):

return "this is in str"

事实上,__str__是被print函数调用的,一般都是return一个什么东西。这个东西应该是以字符串的形式表现的。如果不是要用str()函数转换。当你打印一个类的时候,那么print首先调用的就是类里面的定义的__str__,比如:str.py

如下脚本:

class  ybl():
name='yubenliu'
def __str__(self):
return self.name
t=ybl()
print t
print t.__str__() print type(t)

返回的结果是:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANAAAABQCAIAAADndmz7AAACuElEQVR4nO2c0XasIAxF/ev7+dOH2+oMhCSIHgfd+6FLI2Do7AGFri4vACHL1QnAs0A4kIJw0MHyiRlc48Wl38gFWcPMFD51B09PEO5F6JZZcgsWJeqxkeAzg45wdbGlYV7dFCMc9LE6WgRbspZqtqrpv1IEvyroC1c4ZwbtWk7TADW+cHGtk9KCuxIObEHw9AThRhRzbj0Xt65uLVyQNTwYhAMpCAdSEA6k7BRuWV7Ri3CqBbORwZbhm9n/2R6iBW49DYQDKcXW1jbNrcfvE199XE+LrSrmBOrXNe8IU1NvtRrH40GzQH0alkG42TH/jGn7+R4pjh236kHObKo+Dcsg3OwcL1yrQbMAwj2N1h+T2KfhuJUPmqf5u8OkpIR7Wc/+XS8NRZWiuj8jm3eHSckKB3AIzWURgDNALpCCcCCFzXuQwl4qSEE4kMLmPUhh8x6ksHkPUti8Byls3oMUNu9BCpv3IIXNe5CCXFLC/752e76r81OPr5nkEc7r/CW/mdZNp/iYElspCNe6kFi/OJyT7nJt8p+v2whnRqNv6lxcnvzbug/C1aHGulq4utZaRSvKd6fYsyxXJJBPKd/mvh79NY5wxXn6EeqQnYY8pgTJG+WTT7a5r0fLgnCJES4Mhh+zM8x0JJrbYDVv4XyLTMleDbfqivkeMcL9Z+gZLi/cOEnhwsJ1cJ9wXfAMt9L9lup/lsopNX+jkYlyvEefhRHOudZ+bPLLhE/ofSlW81d4bObppOq030o+2aOqFsIN1k9MXrCCcDs7f/gw9hAQ7tGdBz0IB1JK4f5ZA34+COAzpBfOQS+2MTgHJ9HUBefgDDxXcA4OhxEOpPAMB1J4SwUprMOBFKQBKQgHUhAOpCAcSEE4kIJwIAXhQArCgRSEAykIB1IQDqQgHEhBOJCCcCAF4UAKwoGUH1JKkjBkasXdAAAAAElFTkSuQmCC" alt="" />

return 返回的只可以是字符串如果是其他的类型就会报错

在PYTHON中默认的类都__STR__这个属性如

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4AAAACtCAIAAABujIZ1AAAePklEQVR4nO2dv8stx3nHtwyoEsKFKxVubLCNOu2ZVEnARSAQYUICAXeCSH+ADakSdSncJc0FEwzBqWWCITF2jOFCLJFUQZXJFcKKc4trBCqN2RR777n77sw8+8zs/N7PhwP37Mzs/PjOM7Pfs3vOe6enT//t3S9Nz/nDv/voo4/++Hv/86VXp2mapsfTq1+aHfzOlTjP8/+9+ntf/Jonb57nef7aF1+VCwAAAADA6ExPnz799a9//atf/erjjz/+5S9/uRrQl/k+rxmaDgAAAAAwz/OxAZ3xoAAAAACQEoUBnfGgAAAAAJAMnQGd8aAAAAAAkAbugAIAAABAUfgOKAAAAAAUhV/BAwAAAEBRRAOK+wQAAACA1PgNKO4TAAAAADKg/hU8AAAAAEAKMKAAAAAAUBQMKAAAAAAUBQMKAAAAAEXBgAIAAABAUYYzoMl/jM+v+wEAAACSMpYBzWQW8aAAAAAA6Wjy74D+Lqo2+5S4epSVAwAAAEAUbfxPSDuniAEFAAAAGJdm/i/4kw6vgNHEgwIAAACkYPr5z3/+s5/97Cc/+cmPf/zjH/3oRz/84Q//4O//++tbPv+6m9B0mbizUp2uqSdVEwAAAADXZvr8888/++yzZ8+ePX369NNPP33y5Mmf/OPHZseyT4hMt4ttX7tEZ0mhgK9yO9GZ6+xMxKAAAAAAQERnQE0GDyo7SJ8FXDwF9N2wfaemHjkLAAAAANTUuwMaZ0CVtQnpEe0eZgEAAACAGoUBzff8XX94WDMGFAAAAKATjgxoJvdplzxpQPWnxBlQ3CcAAABAIkQDms997gpr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bRhY0IBQMaBwZUTle2oq9ZGVcYUE27ERfOYqTaz3Mb0JN6NrI/6A2op8M+6/nJPOeynlYfHL0V0oVxyU3YiZ3Ou/6ib8LHG9d6Nk4b0MMJc1p1u7CvwkwXWj12H0qST2dNnWeoqJtGtGIbTSodhDl1puzSlX2Iu8AbV/g5By7bC2cH7BpSzZczBnIY0EWhz+Ip7OtGLd3O7OdB6akM6Hk9g3RLu+/pe+4Zr9N6vif4zhxxYvfWbutwXM7ThXb7nffDvcV4BqK/LoS2no0Tf4h+sQYvXHWWTTw5zzosf9hEPspOiaP1aJ0Xz+nOU3L0vDy2ArssvZ4Ju5SqEmGx+IagHJpQz2Eg7QLP7ravP4fx6etqKs6PV+iYbx/zneLcJO1coZ8yqXTT7+fKQ18gObey0Pp3nTRWrj2uk/tDqvUepI/zzUMD+sk8v/cvilue5/sftF0sunHp56XfedeMy9d/k2IIJlH0qmn7f0JqhLJTMg7otnIpHezNMXcTdVk87zXllaekoindBqYlnX/74u/JP7/rGRGioKRr3eLc6mk8BtT5obMjfX39jxhXjo+zZ/qTFXRL3m5Tq6ZMvGWN5Kb0NFGDrbLSW9NtVBrT+YN5fuc/bwHx1lj/uwHdouAOKAAAAAAUBQMKAAAAAEXBgAIAAABAUTCgAAAAAFAUDCgAAAAAFMVvQH2/6gpNBwAAAADYIN4BxYMCAAAAQGqOHsHjQQEAAAAgKYrvgOJBAQAAACAduh8h4UEBAAAAIBHqX8HjQQEAAAAgBdwBBQAAAICi8B1QAAAAACgKv4IHAAAAgKLwd0ABAAAAoCh1/iek//IQ1HUAAAAA6JE6/xc8BhQAAADgsvw/JpGybv/y/WgAAAAASUVORK5CYII=" alt="" />

用于print调用如:

>>> t={}

>>> t['1'] = "hello"

>>> t['2'] = "world"
>>> t   #等于 print t
{'1': 'hello', '2': 'world'}
>>> t.__str__()
"{'1': 'hello', '2': 'world'}"

大家可以看到一个字典,print t 和 t.__str__()是一样的。只不过__str__()将字典内容以字符串形式输出

关于__str__的介绍的更多相关文章

  1. python特殊函数__str__、__repr__和__len__

    1.__str__ 首先介绍__str__ class Students(object): def __init__(self, *args): self.names = args # def __s ...

  2. day25:魔术方法

    目录 1.__del__(析构方法) 2.魔术方法:__str__ 3.魔术方法:__repr__ 4.魔术方法:__call__ 5.魔术方法:__bool__ 6.魔术方法:__add__& ...

  3. python常用数据类型内置方法介绍

    熟练掌握python常用数据类型内置方法是每个初学者必须具备的内功. 下面介绍了python常用的集中数据类型及其方法,点开源代码,其中对主要方法都进行了中文注释. 一.整型 a = 100 a.xx ...

  4. 基于python的知乎开源爬虫 zhihu_oauth使用介绍

    今天在无意之中发现了一个知乎的开源爬虫,是基于Python的,名字叫zhihu_oauth,看了一下在github上面star数还挺多的,貌似文档也挺详细的,于是就稍微研究了一下.发现果然很好用啊.就 ...

  5. Python入门之函数的介绍/定义/定义类型/函数调用/Return

    本篇目录: 一. 函数的介绍 二. 函数的定义 三. 定义函数的三种类型 四. 函数调用的阶段 五. Return返回值 ======================================= ...

  6. python中int的功能简单介绍

    Int的功能介绍 1. 绝对值 x.__abs__()等同于abs(x) 2. 加法 x.__add__(y)等同于x+y 3. 与运算 x.__and__(y)等同于x&y 4. 布尔运算 ...

  7. ORM基础之ORM介绍和基础操作

    一.ORM介绍 1.ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过 ...

  8. Django ----- app 和 ORM的操作和介绍

    创建APP ORM 介绍 ORM的操作 说明一下 GET 和 POST 的区别: , GET ①获取一个页面 ②提交数据 数据显示在URL ?user=alex&pwd=alexdsb ,PO ...

  9. 对于stark(curd)插件的使用简单介绍

    一.创建表 from django.db import models from django.db import models class Department(models.Model): &quo ...

随机推荐

  1. 鼠标悬浮触发事件(onmouseover)实现

    将鼠标移至(悬浮)到某个标签范围内触发事件或提示消息等效果实现的关键词为:onmouseover. 代码: <!DOCTYPE html> <html> <head> ...

  2. BZOJ 2820: YY的GCD 莫比乌斯反演_数学推导_线性筛

    Code: #include <cstdio> #include <algorithm> #include <cstring> #include <vecto ...

  3. ivew Modal rule校验冲突问题

    问题描述:新建和编辑公用的是一个弹框,打开新建关闭之后,会影响到编辑的弹框.  解决方法:赋值前先重置一下表单  this.$refs["你的表单"].resetFields();

  4. Codeforces 667B Coat of Anticubism

    链接:传送门 题意:题目balabala说了一大堆,然而并没什么卵用,给你n个数,将这个集合分割成两部分,构成三角形的两个边,让你求补充的那个边最短是多长 思路:三角形三边具有 a + b > ...

  5. [luogu] P2569 [SCOI2010]股票交易 (单调队列优化)

    P2569 [SCOI2010]股票交易 题目描述 最近 \(\text{lxhgww}\) 又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,\(\te ...

  6. Ubuntu下使用crontab部署定时任务

    Ubuntu下使用crontab部署定时任务 安装cron apt-get install cron 开启crontab日志 默认情况下的日志是没有开启的,我们需要找到 /etc/rsyslog.d/ ...

  7. Windows里正确安装Zookeeper以服务运行

    不多说,直接上干货! 为什么要在Win下来安装Zookeeper呢? 其实玩过大数据的人很清楚,在Linux下我更不说了.在win下,如Disconf .Dubbo等应用. 所以,它的应用是非常广的. ...

  8. angular-resource

    上一篇中讲到使用$http同服务器进行通信,但是功能上比较简单,angularjs还提供了另外一个可选的服务$resource,使用它可以非常方便的同支持restful的服务单进行数据交互. 安装 n ...

  9. 模式匹配的KMP 算法

    常见的字符串匹配时,模式串长度为n,源串长度为m,则从头匹配,两个指针i指向源串,j指向模式串,如遇到不同则回溯使j=0,这样就要反复匹配会使效率变低. 因为在如今i之前 的模式串与匹配串的匹配是同样 ...

  10. JSP简单练习-上传文件

    注意:在编写上传文件的代码时,需确保"WEB-INF/lib"下含有jspsmartupload.jar包.否则会出错. jspSmartupload.jar下载 <!-- ...