二者功能差很少,都是把对象转为字符串表示形式,可是也有区别,repr()以后再eval()能够转为原型,但str()只能保证大多数,不能100%python
其中主要的 差异在与 字符串对象自己,好比 a = 'god', 则 repr(a) ===>" 'god' " ,而str(a) ===> ' god '函数
python的格式化输出中,对与字符串,%r 表明优先用repr()进行字符串转换, %s表示优先用str()进行字符串转换spa
print()函数调用的是str()函数对象