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.

Python String Formatting: Recap & Summary

Give Feedback

Summary of what you’ve learned in this course:

  • String Format with %
  • String Format with .format()
  • f-strings
  • Template Strings

Knowing which method to use to format strings can be confusing, In this lesson you’ll see a handy flowchart to help you decide which formatting method to use.

philraffsr on April 11, 2019

Simple and straightforward. Would like to have seen some decimal/left-right justification/zero-fill examples.

Wiggers on April 11, 2019

Why in books does it do this print('Hey ' ;name; 'There is an error '; string(errno) ? It confused me the first time some one put f strings in my code!

Eriberto on April 12, 2019

Formatting using the f-string method is the one i preferred the most.

Pavel Zaikin on April 14, 2019

A lot of examples: pyformat.info

Malef on April 14, 2019

Thank for straightforward and informative way of presenting information.

adriaprat on April 15, 2019

As philraffsr said, some decimal/left-right justification/zero-fill examples would be nice. 😉

gracebr28 on June 4, 2019

Thanks for the great tutorial!

Abby Jones on June 27, 2019

Very informative!

aradim on July 14, 2019

Very nice! Thank you.

Pakorn on Dec. 17, 2019

great tutorial

alvesmig on June 28, 2020

Thank you for this great tutorial

dannysharkey80 on Aug. 13, 2020

What is meant by a “user supplied format string”? I’m not sure understand the use-case.

Bartosz Zaczyński RP Team on Aug. 14, 2020

User-supplied strings would be anything that comes from your application’s users rather than you as the author. It could be a comment left on a website or something typed on the keyboard in a command-line app.

For security reasons, you should always assume that such external content may potentially contain malicious data that requires special treatment. Using a template string is safer than all the other methods because it has some countermeasures to prevent the attacks.

Yvonne Wilmot on Sept. 23, 2020

Thanks a lot. That clarified where the different ways of string formatting fit in and when/where each method is supposed to be used.

Become a Member to join the conversation.