Python: Printing with .format()

Another way to print variable values in Python is the .format(). This method replaces %d,%s, and %r, but I still showed them to you in an earlier lesson as you will still see them in use, I wanted you to know about them.

When using .format() – {} represents your place holder in the string.

Screenshot 2022-07-04 204102

You can also use numbers to tell format which order to use values in.

Screenshot 2022-07-04 204336

You can name your place holders:

Screenshot 2022-07-04 204624

You can use user input:

Screenshot 2022-07-04 205204

Try your code in our online Python console:  

Last Page: Print variables and user input

Next Page: Lists and Dictionaries

Back to Python Course: Course

Leave a Reply