+1

[Solved]Difference between %r & %s? Any explanation on the below code is also welcome

https://code.sololearn.com/c45MFtoF06dT/?ref=app

9/11/2019 7:20:44 AM

Subham

6 Answers

New Answer

+2

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

+2

As mentioned by KfirWe , the %r uses the repr() function when representing a value while %s uses the str() function. While the purpose of str() is to represent that value in a readable way to the developer and normal user alike, repr() is used to represent the Python object in a way that could be useful to the developer. For most cases, it will output the same thing as str(), but in other cases (generally involving objects) will output more specific information (this forum explains it quite well - https://www.quora.com/What-are-the-differences-among-s-r-and-d-in-Python )

+1

Subham here you hace everything you need to know https://www.google.com/amp/s/www.geeksforgeeks.org/str-vs-repr-in-python/amp/

0

What is repr?

0

Faisal !

0

Only understood somewhat If I can use %r more practically, for debugging I will understand it better. I wish I was software engineer working on Python But I am working with books, Python crash course & Learn python the hardway 3