共計 433 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 Python 中,使用 print 語句可以將數據輸出到控制臺或者文件中。以下是一些使用 print 語句的示例:
- 輸出字符串:
print("Hello, World!")
- 輸出變量的值:
name = "Alice"
age = 25
print(name)
print(age)
- 輸出多個變量的值:
x = 10
y = 20
print("x =", x, "and y =", y)
- 格式化輸出:
name = "Bob"
age = 30
print("My name is {} and I am {} years old.".format(name, age))
- 使用轉義字符:
print("This is a new line.\nThis is a tab.\tThis is a backslash: \\")
注意:在 Python 2.x 版本中,print 是一個語句而不是函數,可以直接使用。而在 Python 3.x 版本中,print 是一個內置函數,需要使用括號將要輸出的內容括起來,例如:print("Hello, World!")
。
丸趣 TV 網 – 提供最優質的資源集合!
正文完