Using multiple arguments for string formatting in Python (e.g., '%s ... %s') -
I have a string that looks like '% s in'% s'
and I know I want to differentiate arguments so that they are two different% s. My brain is coming from Java:
'% s in% s'% Unicode (auto author), Unicode Publication)
But this does not work, how does it look in Python?
Mark Ciadde's answer is correct - you need to supply a tuple.
However, after Python 2.6 you can use instead of %
:
{0} in {0}. Formats (Unicode (self-author, 'UTF-8'), Unicode (Autocomplete, 'UTF-8'))
%
for formatting strings now Is not encouraged.
This method of string formatting is the new standard in Python 3.0, and the new code should be preferred for% formatting described in string formatting operations.
Comments
Post a Comment