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函數的幾種基本用法,根據具體需求可以靈活運用。