共計 369 個字符,預計需要花費 1 分鐘才能閱讀完成。
要在 Python 中打印信息,可以使用 print() 函數。print() 函數用于輸出文本或變量值。
以下是兩個例子:
- 打印文本:
print("Hello, World!")
結果輸出:
Hello, World!
- 打印變量值:
name = "John"
print("My name is", name)
結果輸出:
My name is John
在 print() 函數中,可以打印多個值,它們會以空格分隔。如果要打印不同類型的變量,可以使用字符串格式化或轉換為字符串再打印。
例如,打印整數和浮點數:
age = 25
weight = 68.5
print("I am", age, "years old and my weight is", weight, "kilograms.")
結果輸出:
I am 25 years old and my weight is 68.5 kilograms.
丸趣 TV 網 – 提供最優質的資源集合!
正文完