Python内置函数之repr()
repr(object)
返回对象的字符串形式。
>>> a = 'hello'
>>> repr(a)
"'hello'"
返回的字符串形式可以通过 eval()函数获取到本来的值。
>>> eval(repr(a))
'hello'
对于一般的实例对象,返回的是由模块、类型及内存地址组成的字符串对象。
可以通过定义类的私有方法 __repr__()来自定义返回的值。
>>> class A:
... def __init__(self,name):
... self.name = name
... def __repr__(self):
... return ('hello' + self.name)
...
>>> a = A('tom')
>>> repr(a)
'hellotom'
Python内置函数之repr()的更多相关文章
- Python内置函数(53)——repr
英文文档: repr(object) Return a string containing a printable representation of an object. For many type ...
- Python内置函数(12)——str
英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string ...
- Python内置函数(61)——str
英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string ...
- Python 内置函数笔记
其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...
- 【转】python 内置函数总结(大部分)
[转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...
- python内置函数,匿名函数
一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...
- python 内置函数总结(大部分)
python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...
- python内置函数大全(分类)
python内置函数大全 python内建函数 最近一直在看python的document,打算在基础方面重点看一下python的keyword.Build-in Function.Build-in ...
- python内置函数和魔法函数
内置方法:Python中声明每一个类系统都会加上一些默认内置方法,提供给系统调用该类的对象时使用.比如需要实例化一个对象时,需要调用该类的init方法:使用print去打印一个类时,其实调用的是str ...
随机推荐
- Sqlserver__数据表排序记录和界面显示排序记录不一致的问题
背景: 数据表中有编号为1-20的20条记录,有一个排序字段OrderIndex, 其中1/3为0,1/3为1,1/3为2 现象: 每次在sqlserver执行OrderIndex ...
- 常见Linux版本
一 常见Linux版本 website feature description http://www.ubuntu.com/ 当前最流行 Ubuntu 正是基于 Debian 之上,旨在创建一个可 ...
- PASCAL 的开源工具
PASCAL 的开源工具: 1)free pascal 代码编译器 http://www.freepascal.org/ 2)lazarus 图形界面开发工具 http://www.la ...
- [转]解决Eclipse更新ADT插件时遇到的Eclipse reports rendering library more recent than ADT plug-in问题
使用 SDK Manager 工具更新下载新版本后,无法显示可视化布局,同时提示 This version of the rendering library is more recent than y ...
- Linux/Unix C编程之的perror函数,strerror函数,errno
#include <stdio.h> // void perror(const char *msg); #include <string.h> // char *strerro ...
- SQL注入深入剖析
SQL注入是一门很深的学问,也是一门很有技巧性的学问 1. 运算符的优先级介绍 2. SQL语句执行函数介绍 mysql_query() 仅对 SELECT,SHOW,EXPLAIN 或 DESC ...
- SQL盲注测试高级技巧
写在前面: 这篇文章主要写了一些加快盲注速度的技巧和盲注中比较精巧的语句,虽然注入并不是什么新技术了.但是数据库注入漏洞依然困扰着每一个安全厂商,也鞭策着每一个安全从业者不断前进. 正文: 首先来简单 ...
- scala类型系统 type关键字
和c里的type有点像. scala里的类型,除了在定义class,trait,object时会产生类型,还可以通过type关键字来声明类型. type相当于声明一个类型别名: scala> t ...
- 批量修改mp3文件的title等
批量修改mp3文件的title等 不是改文件名哦: 下载地址:https://mp3tag.en.softonic.com/ 帮助文档:file:///C:/Program%20Files%20(x8 ...
- vue - helloWorld
1.cdn概念:cdn全称内容分发网络,也是加速服务之一. 2.数据绑定:{{data}} 3.el属性(挂载对象):el:标签任意(例如:#app,.app,app) 4.data:{} => ...