In this course, you mastered two additional techniques that you can use in Python to format string data. You should now have all the tools you need to prepare string data for output or display!
You might be wondering which Python formatting technique you should use. Under what circumstances would you choose
.format() over the f-string? See Python String Formatting Best Practices for some considerations to take into account.
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
Mark Walle on Nov. 24, 2020
We learned about
.format()before f-String literals because you wanted us to understand the precursor function before learning the syntactic sugar version of it.
In the same way, I would like to see a tutorial showing string interpolation using the printf-style (that uses the ‘
%‘ interpolation operator) (docs.python.org/3/library/stdtypes.html#old-string-formatting), which is more like a “C style” string interpolator (which would make it the ultimate “under the hood” approach to borrow your phrase).
I would also argue that “%” style interpolation is still relevant: it helps us to understand why the
.format()function is so handy to have in the first place; and it is also remains relevant in terms of its use for the python logger module to format messages using late-evalution for it’s performance advantage.
Please consider a tutorial on it as part of a larger course on strings.