python 内建函数 str() 和 repr() 的区别
2017-12-15 11:05
363 查看
1.str()一般是将数值转成字符串,str()函数得到的字符串可读性好(故被print调用)
2.repr()是将一个对象转成字符串显示,repr() 函数将对象转化为供解释器读取的形式。支持dict和list。
repr是representation及描述的意思,不是对人的描述,而是对python机器的描述,也就是它会将某物返回一个它在python中的描述。对python友好。
repr()函数得到的字符串通常可以用来重新获得该对象,通常情况下 obj==eval(repr(obj)) 这个等式是成立的。
3.python里的str()也能把列表、字典等对象转成字符串。对用户友好
2.repr()是将一个对象转成字符串显示,repr() 函数将对象转化为供解释器读取的形式。支持dict和list。
repr是representation及描述的意思,不是对人的描述,而是对python机器的描述,也就是它会将某物返回一个它在python中的描述。对python友好。
repr()函数得到的字符串通常可以用来重新获得该对象,通常情况下 obj==eval(repr(obj)) 这个等式是成立的。
3.python里的str()也能把列表、字典等对象转成字符串。对用户友好
相关文章推荐
- Python菜鸟晋级03----repr() 与str() 函数的区别
- Python中str()和repr()函数的区别
- python 内建函数 str() 和 repr() 的区别
- python 内建函数 str() 和 repr() 的区别
- Python中__repr__和__str__区别
- Python repr() 或str() 函数, 反引号
- python的class的__str__()和__repr__()函数
- [python]python中str()与repr()的区别与联系
- Python 格式化输出 —— %r 与 %s 的区别(__repr__ 与 __str__)
- Python中__repr__和__str__区别
- python中__str__和__repr__的区别
- python str和repr的区别
- python中str()与repr()区别
- 详解Python中__str__和__repr__方法的区别
- python的str()和repr()的区别
- python str与repr的区别
- python中str()和repr()的区别
- python __str__, __repr__的区别
- python的str()和repr()的区别
- 【再回首Python之美】【类-特殊方法】__str__()和__repr__()的区别和重写覆盖