在Python中,data可以表示數據的不同形式、類型和結構。以下是data在Python中的常見用法:
示例:
x = 5
y = "Hello"
示例:
mylist = [1, 2, 3, "four", 5.0]
print(mylist[0]) # 輸出: 1
mylist[3] = "four"
print(mylist) # 輸出: [1, 2, 3, "four", 5.0]
示例:
mydict = {"name": "John", "age": 25, "city": "New York"}
print(mydict["name"]) # 輸出: John
mydict["age"] = 26
print(mydict) # 輸出: {"name": "John", "age": 26, "city": "New York"}
示例:
mytuple = (1, "two", 3.0)
print(mytuple[1]) # 輸出: two
示例:
mystr = "Hello, World!"
print(mystr[7:]) # 輸出: World!
這些是data在Python中的常見用法,但還有其他更多的數據類型和數據結構可以用來處理和操作數據。