Python中的print函數(shù)用于在控制臺(tái)輸出文本或變量的值。以下是幾種常見(jiàn)的使用方式:
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函數(shù)的幾種基本用法,根據(jù)具體需求可以靈活運(yùn)用。