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'

 

相关文章:

  • 2022-01-15
  • 2021-06-03
  • 2021-11-07
  • 2021-11-07
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-05
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2021-12-18
  • 2021-06-03
相关资源
相似解决方案