39. """
讀取input.txt
"""
# Initialize the input_string variable.
input_string = ""
# Load input.txt content to input_string.
with open('input.txt', 'r') as file:
input_string = file.read()
# Display the input_string int the result.
input_string
解讀程式碼細節 (1/5)
39
40. """
讀取input.txt
"""
# Initialize the input_string variable.
input_string = ""
# Load input.txt content to input_string.
with open('input.txt', 'r') as file:
input_string = file.read()
# Display the input_string int the result.
input_string
解讀程式碼細節 (2/5)
多行註解
40
以"""開頭,以"""結尾
多行註解
說明程式的用途
41. """
讀取input.txt
"""
# Initialize the input_string variable.
input_string = ""
# Load the content of input.txt to input_string.
with open('input.txt', 'r') as file:
input_string = file.read()
# Display the input_string int the result.
input_string
解讀程式碼細節 (3/5)
單行註解
41
# 之後的內容
單行註解
說明以下程式,
或是前面程式的用途
42. """
讀取input.txt
"""
# Initialize the input_string variable.
input_string = ""
# Load the content of input.txt to input_string.
with open('input.txt', 'r') as file:
input_string = file.read()
# Display the input_string int the result.
input_string
解讀程式碼細節 (4/5)
程式碼
42
其他的部分
程式碼
實際上要執行的程式碼。
教學中會修改部分內容。
43. """
讀取input.txt
"""
# Initialize the input_string variable.
input_string = ""
# Load the content of input.txt to input_string.
with open('input.txt', 'r') as file:
input_string = file.read()
# Display the input_string int the result.
input_string
解讀程式碼細節 (5/5)
舉例
43
讀取input.txt的內容到
input_string變數。
以唯獨模式
開啟input.txt檔案
讀取檔案內容到
input_string