Site icon Analytics4All

Python: Printing with .format()

Advertisements

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.

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

You can name your place holders:

You can use user input:

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

Exit mobile version