0
点赞
收藏
分享

微信扫一扫

Python-字典(练习题)

"""练习题"""cities = {
'Wuhan': {
'country': 'China',
'population': '1700',
'fact': 'nice' },
'New York':{
'country': 'America',
'population': '1600',
'fact': 'good'
},
'Paris':{
'country': 'French',
'population': '1000',
'fact': 'normall' }
}
for city_name,city_info in cities.items():
print('city_name:'+city_name)
country = city_info['country']
population = city_info['population']
fact = city_info['fact']
print('country:'+country+'\t'+'population:'+population+'\t'+'fact:'+fact+'\n')

"""添加键和值"""
cities['Wuhan']['history'] = 100
print(cities.items())
"""修改键和值"""
cities['Wuhan']['history'] = 50
print(cities.items())
"""删除键和值"""
del cities['Wuhan']['history']
print(cities.items())

举报

相关推荐

python-纸牌小游戏练习题

python 练习题

python练习题

Python练习题

python 练习题-质数

Python列表练习题

【Python】函数练习题

0 条评论