How to Use Named Indexes When Using Format() Method in Python


In this example we will show how to use named indexes when using the format() method in Python.

Source Code

name = 'Jim'
age = 16
city = 'New York'

print('I am {name}, {age} years old, from {city}.'.format(name=name, age=age, city=city))

Output:

I am Jim, 16 years old, from New York.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments