name = "Alice"
age = 30
message = "My name is {} and I am {} years old.".format(name, age)
print(message)
name = "Alice"
age = 30
message = "My name is {1} and I am {0} years old.".format(age, name)
print(message)
num = 123.456789
formatted_num = "{:.2f}".format(num)
print(formatted_num) # 输出:123.46
from datetime import datetime
now = datetime.now()
formatted_date = now.strftime("%Y-%m-%d %H:%M:%S")
print(formatted_date)
person = {"name": "Alice", "age": 30}
message = "My name is {name} and I am {age} years old.".format(**person)
print(message)
items = ["apple", "banana", "cherry"]
message = "I like {} and {} and {}.".format(*items)
print(message)