Python中如何处理嵌套字典?

2026-06-10 23:390阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计79个文字,预计阅读时间需要1分钟。

Python中如何处理嵌套字典?

字典中嵌套字典,直接输出结果:username: wenusername: tao

Python中如何处理嵌套字典?

"""字典中嵌套字典"""users = {
'wen': {
'first': 'zhou', 'last': 'wen', 'location': 'hubei' }, 'tao': {
'first': 'zhou', 'last': 'tao', 'location': 'hubei' }
}

for username,userinfo in users.items():
print('username:'+username)
fullname = userinfo['first']+userinfo['last']
location = userinfo['location']
print('fullname:'+fullname)
print('location:'+location)
print('\t')

本文共计79个文字,预计阅读时间需要1分钟。

Python中如何处理嵌套字典?

字典中嵌套字典,直接输出结果:username: wenusername: tao

Python中如何处理嵌套字典?

"""字典中嵌套字典"""users = {
'wen': {
'first': 'zhou', 'last': 'wen', 'location': 'hubei' }, 'tao': {
'first': 'zhou', 'last': 'tao', 'location': 'hubei' }
}

for username,userinfo in users.items():
print('username:'+username)
fullname = userinfo['first']+userinfo['last']
location = userinfo['location']
print('fullname:'+fullname)
print('location:'+location)
print('\t')