13,420
edits
Changes
→PART 2 - String Formatting
:#To demonstrate, issue the following:<source>
print('{} {} {}'.format('a', 'b', 'c'))
</source>However, using this method while quick, easy, and clean has a issue. If more curly braces '''{}''' are in the string than in the format() arguments, it will create a an '''error'''.<br><br>
:#To demonstrate by creating too many braces, issue the following:<source>
print('{} {} {} {}'.format('a', 'b', 'c'))
</source>:#For situations like above, if reusing strings more than once is important, '''positional values''' can be placed inside the curly braces.<br><br>
:#Issue the following to see what happens:<source>
print('{0} {1} {1} {2}'.format('a', 'b', 'c'))