How can we achieve the following in Python 3.6 using f-string (instead of using format()
) method?
quantity = 3
itemno = 567
price = 49
myorder = "I want {0} pieces of item number {1} for {2:.2f} dollars."
print(myorder.format(quantity, itemno, price))
Output:
I want 3 pieces of item number 567 for 49.00 dollars.
print(f"I want {quantity} pieces of item number {itemno} for {price:.2f} dollars.")
? ormyorder = f"I want {quantity} pieces of item number {itemno} for {price:.2f} dollars."
--- because both worked when I ran them in ipython. So I'm not sure what you're asking.