what the difference between %r & %s
hi all:)
i was learning from learnpythonthehardway.org
Exercise 14: Prompting and Passing
he write %r & %s !!!!
what the difference between %r & %s !!
Those %r and %s are placeholders for the actual text you'll see later when the code actually runs. You send an object to the print command for each %r, %s and any other "%" that should be replaced and python has to translate that object to text somehow so those placeholders can be replaced. When you use %r python will call the "repr" method with the object that corresponds to that position as a parameter, and will replace %r with the result or "repr()". When you use %s python will use a different method, "str".
Your classes should implement those methods in a way that makes sense, accodring to the documentation:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement