Using format instead of %s for string replacement


Usually we use “%s” for string replacement in Python:

1
"asddas %s" % (‘hello’,)

There is better way to do it:

1
2
3
"hello {a} {b} {c}".format(a=’error’, b=’hello’, c=’world’)
"hello {0} {1} {2}".format("hello", "world", "fine")
"hello {}".format("hello")

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.