wesm / pydata-book

Materials and IPython notebooks for "Python for Data Analysis" by Wes McKinney, published by O'Reilly Media
Other
22.27k stars 15.19k forks source link

In chapter 2, print(template) is not giving expected answer as the original string never get changed by this format #183

Closed AnCyNitinChaudhary closed 1 year ago

AnCyNitinChaudhary commented 1 year ago

Your Code: template="{0:.2f} {1:s}are worth US${2:d}" template.format(4.5667,'Argentine Pesos',1) print(template)

Output Your Code: {0:.2f} {1:s}are worth US${2:d}

Updated Code: template="{0:.2f} {1:s}are worth US${2:d}".format(4.5667,'Argentine Pesos',1) print(template)

Output Updated Code: 4.57 Argentine Pesosare worth US$1

wesm commented 1 year ago

This is fixed in the 3rd edition, you can see the new code here:

https://wesmckinney.com/book/python-basics#scalar_strings