Input and Output

Python has ways to convert any value to a string: pass it to the repr() or str() functions.

这两者都是将值转变为string类型,但是有区别:

str()得到的string类型变量会执行转义等命令,而repr()则直接照搬。

hello = 'hello, world\n'
hellos = repr(hello)
helloss = str(hello)
print(hellos)
print(helloss)
print(hellos)


'hello, world\n'
hello, world

'hello, world\n'

 

posted @ 2018-06-18 14:11  nichoo的博客  阅读(302)  评论(0编辑  收藏  举报