String Formatting
String formatting allows inserting values into strings.
Using format()
format()
name = "John"
age = 25
print("My name is {} and I am {} years old.".format(name, age))
Output
My name is John and I am 25 years old.
Multiple Placeholders
product = "Laptop"
price = 50000
print("Product: {}, Price: ₹{}".format(product, price))
Output
Product: Laptop, Price: ₹50000
Positional Arguments
print("{1} is learning {0}".format("Python", "Alice"))
Output
Alice is learning Python