Python f-string cheat sheets (2022)
Python f-string cheat sheets See fstring.help for more examples and for a more detailed discussion of this syntax see this string formatting article. All numbers The below examples assume the following variables: >>> number = 4125.6 >>> percent = 0.3738 Example Output Replacement Field Fill Width Grouping Precision Type '4125.60' {number:.2f} .2 f '4,125.60' {number:,.2f} , .2 f '04125.60' {number:08.2f} 0 8 .2 f ' 4125.60' {number: 8.2f} 8 .2 f '4.1e+03' {number:.2g} .2 g '4125.6' {number: