在Python中,可以使用以下方法來保存變量數據:
x = 10
my_list = [1, 2, 3, 4, 5]
my_tuple = (1, 2, 3, 4, 5)
my_set = {1, 2, 3, 4, 5}
my_dict = {"name": "John", "age": 25, "city": "New York"}
# 寫入數據到文件
with open("data.txt", "w") as file:
file.write("Hello, world!")
# 從文件中讀取數據
with open("data.txt", "r") as file:
data = file.read()
這些方法可以根據需求選擇適合的方式來保存變量數據。