在python中,将对象转换为字符串有两个内建函数: str Vs repr .str 是一个友好的,人们可读的字符串.repr 应该包含关于对象内容的详细信息(有时他们会返回相同的内容,例如整数).按照惯例.如果有一个python表达式将评估另一个 == 对象,repr 将会返回这样的表达式,>>> print(repr("hi"))"hi" # notice the quotes here as opposed to ...>>&g…
str()一般是将数值转成字符串. repr()是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思.如list,dict使用str()是无效的,但使用repr可以,这是为了看它们都有哪些值,为了显示之用. The str() function is meant to return representations of values which are fairly human-readable, while repr() is meant to generate rep…