python 在打印一个实例化对象时,打印的是对象的地址,比如:<__main__.Workers object at 0x00000000255A9AC8>

而__str__(self)就可以打印具体的属性,用法如下:

def __str__(self):
msg = "姓名:{},工号:{},工资:{}".format(self.name,self.number,self.salary)
return msg

在打印实例化对象时打印的内容:

姓名:**,工号:0001,工资:3600

Python __str__(self)的更多相关文章

  1. python __str__ & __repr__ & __cmp__

    For ( __str__ ),we going to see a example ... and find who is working for ... #!/usr/bin/python clas ...

  2. python __str__() 和 __repr__()是干啥的

    1. 没定义__str__() print的时候得不到自己想要的东西 类默认转化的字符串基本没有我们想要的一些东西,仅仅包含了类的名称以及实例的 ID (理解为 Python 对象的内存地址即可).虽 ...

  3. Python __str__函数

    class Cat: def __init__(self,_name): self.name = _name def __str__(self): return "i am %s" ...

  4. python __str__ , __repr__区别

    Python 有办法将任意值转为字符串:将它传入repr() 或str() 函数. 函数str() 用于将值转化为适于人阅读的形式,而repr() 转化为供解释器读取的形式 (如果没有等价的语法,则会 ...

  5. python - __str__ 和 __repr__

    内建函数str()和repr() (representation,表达,表示)或反引号操作符(``)可以方便地以字符串的方式获取对象的内容.类型.数值属性等信息.str()函数得到的字符串可读性好(故 ...

  6. Python __str__(self)和__unicode__(self)

    object.__str__(self) Called by the str() built-in function and by the print statement to compute the ...

  7. python __str__ 和__repr__方法

    看下面的例子就明白了 class Test(object): def __init__(self, value='hello, world!'): self.data = value >> ...

  8. SQLAlchemy on the way

    SQLAlchemy Trial This is a great ORM ( Object-Relational Mapper ) which is compatible with  xxxx and ...

  9. Django学习笔记(3)——表单,测试和模板语法的学习

    一,表单form 为了接收用户的投票选择,我们需要在前段页面显示一个投票界面,让我们重写之前的polls/detail.html文件,代码如下: <h1>{{ question.quest ...

随机推荐

  1. 有关for循环的一些东西

    有的时候,不知道是因为学的有点浅显,还是脑袋有点懵,简单的循环语句都有点被绕糊涂了. 这种内外循环的,先是外循环一次,内循环全部,接着再外循环第二次,内循环全部,,,,,,,. 所以先是显示 0 4 ...

  2. Muduo网络库实战(一):安装和配置

    1. 参考资料 <Muduo_网络库使用手册> 2. 实战记录 1) muduo依赖项安装 centos安装cmake命令:# yum install cmake centos安装libb ...

  3. Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)

    To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a ...

  4. 数学--数论-- HDU 2601 An easy problem(约束和)

    Problem Description When Teddy was a child , he was always thinking about some simple math problems ...

  5. HTML(标题/图片/链接/列表标签)

    <!DOCTYPE html> 声明 <!DOCTYPE html> 是 html5 标准网页声明,全称为 Document Type HyperText Mark-up La ...

  6. http抓包—Content-Type讲解

    1.Content-Type的定义 Content-Type(MediaType),即是Internet Media Type,互联网媒体类型,也叫做MIME类型.在互联网中有成百上千中不同的数据类型 ...

  7. redis-py中的坑

    今天发现,使用redis-py从redis中获取的数据竟然是加密的. conn = redis.Redis(host='redis_serverip', port=6379, password='re ...

  8. 最长递增子序列(Longest increasing subsequence)

    问题定义: 给定一个长度为N的数组A,找出一个最长的单调递增子序列(不要求连续). 这道题共3种解法. 1. 动态规划 动态规划的核心是状态的定义和状态转移方程.定义lis(i),表示前i个数中以A[ ...

  9. 组合模式(c++实现)

    组合模式 目录 组合模式 定义 动机 UML类图 场景拆解 源码实现 优点 缺点 定义 将对象组合成树形结构以表示"部分-整体"的层次结构.组合模式是的用户对单个对象和组合对象的使 ...

  10. Awareness Kit让你的音乐APP脱颖而出,更懂用户,也更动人心

    让你的音乐APP脱颖而出,更懂用户,也更动人心. 场景 情景感知服务能带来什么?   作为音乐发烧友,闲下来的时候总想打开App,享受沉浸在音乐中的放松.然而,App推荐的歌单经常没法满足我的需要,如 ...