陳彥勳_派神PYTHON陣列ARRAY串列LIST
import random
import string
random_data = random.sample(string.ascii_uppercase, len(string.ascii_uppercase))
animal_list = random_data[:4]
print("列表:", animal_list)
animal_tuple = tuple(random_data[4:8])
print("元組:", animal_tuple)
animal_set = set(random_data[8:12])
print("集合:", animal_set)
animal_dict = {random_data[i]: random_data[i+1] for i in range(12, 24, 2)}
print("字典:", animal_dict)
animal_list.append(random.choice(string.ascii_uppercase))
print("添加元素後的列表:", animal_list)
animal_tuple = animal_tuple + (random.choice(string.ascii_uppercase),)
print("添加元素後的元組:", animal_tuple)
animal_set.add(random.choice(string.ascii_uppercase))
print("添加元素後的集合:", animal_set)
animal_dict[random.choice(string.ascii_uppercase)] = random.choice(string.ascii_uppercase)
print("添加元素後的字典:", animal_dict)
slice_list = animal_list[1:3]
print("列表切片 (1到3):", slice_list)
another_set = set(random.sample(string.ascii_uppercase, 4))
intersection = animal_set.intersection(another_set)
union = animal_set.union(another_set)
difference = animal_set.difference(another_set)
print("集合交集:", intersection)
print("集合並集:", union)
print("集合差集:", difference)
keys = animal_dict.keys()
values = animal_dict.values()
items = animal_dict.items()
print("字典鍵:", keys)
print("字典值:", values)
print("字典項目:", items)
追求完美的執行https://chenyenhsun.blogspot.com/2025/03/javascriptpython.html
回覆刪除我後來訂正,陳Angle brsces.https://chenyenhsun.blogspot.com/2025/03/pythonlistarraytuplesetdict.html
304.https://chenyenhsun.blogspot.com/2025/03/pythonarraylist.html