Python中的print函数用于在控制台输出文本或变量的值。以下是几种常见的使用方式:
print("Hello, World!")
name = "Alice"
print("Hello, " + name)
age = 30
print("Name:", name, "Age:", age)
print("My name is {} and I am {} years old.".format(name, age))
print(f"My name is {name} and I am {age} years old.")
with open("output.txt", "w") as f:
print("Hello, World!", file=f)
以上是print函数的几种基本用法,根据具体需求可以灵活运用。