wesm / pydata-book

Materials and IPython notebooks for "Python for Data Analysis" by Wes McKinney, published by O'Reilly Media

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

AnCyNitinChaudhary opened this issue · comments

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

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

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