xxxxxxxxxx
name = "Alice"
age = 25
balance = 1234.56789
# Basic formatting using placeholders
print("My name is %s, I am %d years old, and I have a balance of $%.2f" % (name, age, balance))
# Using the format() method
print("My name is {}, I am {} years old, and I have a balance of ${:.2f}".format(name, age, balance))
# Using f-string (Python 3.6+)
print(f"My name is {name}, I am {age} years old, and I have a balance of ${balance:.2f}")
xxxxxxxxxx
from datetime import datetime
'{:%Y-%m-%d %H:%M}'.format(datetime(2001, 2, 3, 4, 5))