October 2017
Beginner to intermediate
464 pages
12h 35m
English
This appendix explains the most common ways to use the format method for string objects, which provides an easy way to print data in nicely structured columns.
Ordinary text in a format specification string is printed as it appears. This includes all text except for curly braces, {}, and the content between them.
Use curly braces, {}, to indicate arguments. This example
’{} plus {} is {}!’.format(4, 6, 10)
prints the following:
4 plus 6 is 10!
{n} is a zero-based index into the argument list. This example
’{2} {1} {0}’.format(10, 20, ...
Read now
Unlock full access