天天看點

weixuan -學習字典-統計參團率

import random
# 參團
ying_xiong = ["亞瑟", "李白", "小喬", "鐘馗", "後羿"]
can_tuan_ying_xiong = []  # 參團英雄清單
# append 安裝軟體--》添加入
# 對參團英雄清單添加一個随機英雄
for nb in range(30):
    ssr = random.randint(0, 4)
    can_tuan_ying_xiong.append(ying_xiong[ssr])
print(can_tuan_ying_xiong)
# 後羿:12  李白:18  小喬:0


# 字典:鍵值對
tongxue = {"姓名": "鋼鐵俠", "同學": "蜘蛛俠", "age": 22}
print(tongxue)
# 增删改查
# 查找方式  字典[索引]
print(tongxue['同學'])
# 修改: 查找要修改的内容 = 被修改成的内容
tongxue["姓名"] = '老八'
print(tongxue)
# 增加: 查找不到的内容 = 被修改成的内容
tongxue["姓名2"] = 'giao哥'
print(tongxue)
# 删除 delete  del 查找删除的内容
del tongxue["age"]
print(tongxue)

print( "姓名" in tongxue )