Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Formatting Python Strings (Summary)

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.


Sample Code (.zip)

2.1 KB


Course Slides (.pdf)

293.5 KB

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) (, 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.

Ghani on Nov. 29, 2020

Thanks for this well-structured and useful course.

jamesbrown68 on Nov. 30, 2020

Thanks, Liam.

thecocoa on Dec. 8, 2020

Thank you, Liam. Very informative.

Become a Member to join the conversation.