str.format() option is not working

format, python, string

Solution

It does work. You were just not assigning the format to a variable, and then just printing the original string. See example below:

>>> s = 'hello, {person}'
>>> s
'hello, {person}'
>>> s.format(person='james')
'hello, james'                    # your format works
>>> print s                       # but you did not assign it
hello, {person}                   # original `s`
>>> x = s.format(person='james')  # now assign it
>>> print x 
hello, james                      # works!

Problem

This code was taken from the tutorial: ``` def main(): stri = "Hello, {person}" stri.format(person="James") print(stri) #prints "Hello, {person}" ``` Why the `format()` is not working?

Original source