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'