如何一起使用Python里for循环和dictionary字典

2024-11-11 08:39:30

1、新建一个空白的PYTHON文档。

如何一起使用Python里for循环和dictionary字典

3、如果直接运用FOR循环,那么只会把关键词显示出来,里面的值不会显示。for details in person: print(details)

如何一起使用Python里for循环和dictionary字典

5、在字典后加.items()可以同时显示关键词和值。for details in person.items(): print(details)

如何一起使用Python里for循环和dictionary字典

7、如果只是字符串就可以单单这样显示即可。for key,value in person.items(): print("Person: " + key + " is " + value)

如何一起使用Python里for循环和dictionary字典
猜你喜欢