This article analyzes the Python string format output method. Share to everyone for your reference, as follows:
There are 3 ways we can format a build string:
1-Tuple placeholder
m = ' python ' astr = ' I love%s '% Mprint astr
2 The Format method of the string
m = ' python ' astr = ' I love {python} '. Format (python=m) print Astr
3 Dictionary formatting strings
m = ' python ' astr = ' I love% (python) s '% {' python ': M}print astr
You can choose the appropriate method according to their actual situation, it is recommended to use the format method of the string or the placeholder formatting of the dictionary, because it will not be affected by the location of the parameter, only need the parameter name is the same line.
More readers interested in Python related content can view the topic: Python string manipulation tips Summary, Python Introductory and Advanced classic tutorials, and Python file and directory Operations Tips Summary
I hope this article is helpful for Python program design.