Which string implementation in python is more pythonic?
string += "<%s>%s</%s>%s" % (a, b, c, d)
or
string += '<' + a + '>' + b + '<'/' + c + '>' + d
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
1 Answer 1
String formatting is faster and more readable, always.
Consider using named parameters, and the more recent str.format() method:
"<{tag}>{value}</{tag}>{tail}".format(tag='foo', value='bar', tail='spam')
answered Mar 5, 2014 at 20:22
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
bagere
That function str.format() looks great for my script. Thank you
Explore related questions
See similar questions with these tags.
lang-py