format () formatted output
format ():% replace the traditional {} for the formatting output
format () common usage:
'{}{}'.format('123', '456') >>>'123456'
In fact, format () behind the content, fill in curly brackets
' Number 1} {2} {0} and { ' .format ( " 123 " , 456, ' 789 ' ) >>> ' numbers 456789 and 123 '
# Note here that there are two braces, only one result output braces ' digital {{1} {2} {0}}} and { ' .format ( " 123 " , 456, ' 789 ' ) >>> ' digital {456789} and 123 '
# Allows two parameters a ' {1} {1} {0} years ' .format ( ' where students ' , 18 ) >>> ' 18 where students 18 years '
# By adding the keyword parameter ' {name}} {Age years ' .format (Age = 18, name = ' where students ' ) >>> ' where students 18 years '
The code also understand the need to understand format () these usages:
: | <Filling> | <Alignment> | <Width> | <,> | <Precision> | <Type> |
Pilot symbols (hereinafter identified special format) |
Character used to fill the (character) | > Align Right <Left ^ Center |
Setting the groove width of the output (digital) | Figures for 1000 separator | Partial precision floating-point or decimal character length (eg: .3f setup packet leaving decimal places) |
b: Binary c: Unicode d: Decimal o: Octal x: hexadecimal e: exponent %: Percentage form
|
Original Reference: https://www.cnblogs.com/runningCsnail/p/10452503.html