The format function of strings in python is very powerful. It can be said that it can completely replace other methods of using strings
Format function example:
The brace usage of format can realize the splicing of strings
The order within the braces can be scrambled, and the order in {} can be written into the format
Retain the decimal point of the output Number
Limit the number of digits in the output number, and also retain the number of decimal places
Thousands separator output
Percent sign output
How does Python use braces in .format
For example: the string hello {name}
'hello {name}.format(name='world')' Brackets are special escape characters. If you need original curly braces, use {{ instead of {, use }} instead of }, as follows:
>>> 'hello {{worlds in braces!}}, {name}'.format(name='zhangsan') 'hello {worlds in braces!}, zhangsan'
The above is the detailed content of How to use braces in .format in Python. For more information, please follow other related articles on the PHP Chinese website!