Technology is always advancing with the progress of the times , Maybe it's because people don't know what they want , Maybe it's because of the wrong mode of thinking at that time , Maybe it's the power of habit . stay Python In the function of , It's also going forward step by step , Its ease of use is also step by step more convenient .Python 3.6 Introduced a new string format f-string, Compared with other formats , Not only is it simple and clear , Better readability , It's not easy to make mistakes , And it's more efficient . You should start using this new format right away , This article will explain the reason and the specific usage . But before that , Let's take a look at f-string Previous string formatting .
All programming developers are getting started , Basically the first level , It's about interacting with a computer , And the easiest way to interact , It's text interaction , Because it's simpler , And accurate enough , It's also fast . When you instruct a computer to do something , I always hope it can give back some information , So that we can know it's doing the right thing , It's still wrong . If the computer looks like a mute , So it outputs nothing , Obviously how boring . Feedback output is always a crucial step , that Python There's a function here print To format the output . At output time , You'll find that some strings are dynamic 、 Variable , You will find that some numbers have to be converted to strings to output .Python Provides the first way to format output ：
This is the most primitive 、 Python The format used in the official guide , Relevant information can be read in the official documents . It is worth noting that , Official documents don't really recommend this approach , The instructions are as follows ：