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

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands 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 your subtitle preferences 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 refer to our video player troubleshooting guide for assistance.

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.

jwimmer on April 13, 2022

Awesome veeery handy :) Especially after I tried really hard to find a solution to how to loop through dictionaries and format the output in a tidy way. As a beginner who aspires to become a game developer I discovered my many basic Python knowledge gaps and work now through Real Pythons Basic, which is a fun and way less distressing way than my previous approach of panicking through book chapters which where too demanding because I was too demanding and didn’t know the solution. I will come back to them at a later point. The video tutorials are also very convenient. They show complex concepts and explain the solution in an easy disgestable / understandable way.

Become a Member to join the conversation.