Python入门习题大全——人2

Python入门习题大全——索引

在为完成上一个“人”例题编写的程序中,再创建两个表示人的字典,然后将这三个字典都存储在一个名为people 的列表中。遍历这个列表,将其中每个人的所有信息都打印出来。

# 人
people = {
    'user1': {
        'first': 'ling',
        'last': 'huihe',
    },

    'user2': {
        'first': 'ze',
        'last': 'xixi',
    }
}
for username, fullname in people.items():
    print(username + "'s fullname is " + fullname['first'].title() +
    " " + fullname['last'].title() + ".") 

输出为:

user1's fullname is Ling Huihe.
user2's fullname is Ze Xixi.
发布了269 篇原创文章 · 获赞 18 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_43479432/article/details/105420122