Python 内建函数 - repr(object)
2017-03-22 16:20
239 查看
Manual
直译
实例
拓展阅读
__repr__()
直译
实例
拓展阅读
Manual
Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method.直译
返回一个字符串,其包含一个对象的可打印的表述形式。对于多数类型,该函数会尝试返回一个字符串,将其传入eval()后返回的值与原对象值相等;否则,该表述是一个封闭在尖括号内的字符串,其包含对象的类型名称和其他附加信息(通常包括对象的名称和地址)。可以通过定义一个类的__repr__()方法来控制该函数为其实例返回的内容。实例
>>> a = repr(range(10)) >>> list(eval(a)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> b = repr(pow(2, 3, 5)) >>> eval(b) 3 >>> c = repr((1+2) / 4) >>> eval(c) 0.75
拓展阅读
eval()__repr__()
相关文章推荐
- Python 内建函数 - repr(object)
- PYTHON函数(isinstance,repr)
- python内建函数hasattr(object, name)
- Python repr() 或str() 函数(转)
- Python学习笔记 --- repr函数介绍
- python的class的__str__()和__repr__()函数
- Python repr() 或str() 函数
- Python 内建函数 - ascii(object)
- python中使用zip函数出现<zip object at 0x02A9E418>
- Python repr() 函数和str() 函数
- Python json序列化时default/object_hook指定函数处理
- Python函数参数传递方式(call by object reference)以及一致性
- Python内建函数str()和repr()
- Python repr() 或str() 函数, 反引号
- python 内建函数 str() 和 repr() 的区别
- Python repr() 或str() 函数
- Python repr() 或str() 函数
- Python repr str 函数
- 【转】Python 里的 super() 函数和 object.__new__ ()、.__del__() 方法
- python中使用zip函数出现<zip object at 0x02A9E418>