共計 547 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 Python 中,可以使用 print() 函數來打印輸出內容。只需要在括號中放入要輸出的內容,并用逗號分隔。例如:
print("Hello, world!")
這將輸出字符串 Hello, world! 到控制臺。你也可以使用多個參數,并在打印時使用逗號分隔它們:
name = "Alice"
age = 25
print("My name is", name, "and I am", age, "years old.")
這將輸出 My name is Alice and I am 25 years old. 到控制臺。你還可以使用特殊的格式化字符串來打印輸出,例如:
x = 10
y = 20
print("The value of x is {} and the value of y is {}".format(x, y))
這將輸出 The value of x is 10 and the value of y is 20 到控制臺。你可以在花括號中使用索引來指定要插入的值的位置,默認情況下它們是按順序插入的:
x = 10
y = 20
print("The value of y is {1} and the value of x is {0}".format(x, y))
這將輸出 The value of y is 20 and the value of x is 10 到控制臺。還有其他許多格式化選項,你可以在文檔中找到更多的信息。
丸趣 TV 網 – 提供最優質的資源集合!
正文完