Python the Hard Way - exercise 6 - %r versus %s

前端 未结 7 684
孤城傲影
孤城傲影 2020-12-04 17:35

http://learnpythonthehardway.org/book/ex6.html

Zed seems to use %r and %s interchangeably here, is there any difference between the two? Wh

相关标签:
7条回答
  • 2020-12-04 18:40

    They are called string formatting operations.

    The difference between %s and %r is that %s uses the str function and %r uses the repr function. You can read about the differences between str and repr in this answer, but for built-in types, the biggest difference in practice is that repr for strings includes quotes and all special characters are escaped.

    0 讨论(0)
提交回复
热议问题