在Python中,可以使用以下幾種形式來存儲數據:
x = 10
y = 3.14
name = "John"
numbers = [1, 2, 3, 4, 5]
fruits = ["apple", "banana", "orange"]
mixed_list = [1, "apple", True, 3.14]
person = ("John", 25, "male")
point = (2, 3)
student = {"name": "John", "age": 25, "gender": "male"}
fruits = {"apple", "banana", "orange"}
numbers = {1, 2, 3, 4, 5}
# 寫入文件
with open("data.txt", "w") as file:
file.write("Hello, World!")
# 讀取文件
with open("data.txt", "r") as file:
data = file.read()
print(data)
這些是Python中常用的數據存儲形式,可以根據需求選擇合適的形式來存儲數據。