Sign in to follow this  

what the difference between %r & %s

Recommended Posts

DiegoSLTS    2113

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:

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this