In python, what does the 2nd % signifies?
print '%s' % ( i )
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As others have said, this is the Python string formatting/interpolation operator. It’s basically the equivalent of sprintf in C, for example:
a = '%d bottles of %s on the wall' % (10, 'beer')is equivalent to something like
a = sprintf('%d bottles of %s on the wall', 10, 'beer');in C. Each of these has the result of
abeing set to'10 bottles of beer on the wall'Note however that this syntax is deprecated in Python 3.0; its replacement looks something like
a = '{0} bottles of {1} on the wall'.format(10, 'beer')This works because any string literal is automatically turned into a str object by Python.