# 定义空字典
dict = {
}
list(列表)可以转成字典,前提是列表中的元素要成对出现
dict3 = dict([('name','lucky'),('age',18)])
print(dict3)
{‘name’: ‘lucky’, ‘age’: 18}
字典的元素添加:dict[key]=value
特点:如果在字典中有同名的key,值会发生覆盖替换;如果没有同名的key,则实现添加功能。
dict4={
}
dict4['brand']='huawei'
print(dict4)
{‘brand’: ‘huawei’}
dict4['brand']='mi'
print(dict4)
{‘brand’: ‘mi’}
dict5={
}
dict5['brand']='huawei'
dict5['type']='Mate30'
dict5['price']='8000'
dict5['color']='紫色'
print(dict5)
{‘brand’: ‘huawei’, ‘type’: ‘Mate30’, ‘price’: ‘8000’, ‘color’: ‘紫色’}
# 案例: 用户注册功能 username,password,email,phone_num
print('- - - - - 欢迎来到XXX用户注册 - - - - - -')
database = []
while T