美文网首页
python items()方法如何使用?

python items()方法如何使用?

作者: Exist_3ebb | 来源:发表于2020-02-24 17:02 被阅读0次

python items()方法如何使用?

Python 字典(Dictionary) items()方法

Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。

推荐:《Python教程

语法

items()方法语法:

dict.items()

参数

NA。

返回值

返回可遍历的(键, 值) 元组数组。

以下实例展示了 items()函数的使用方法:

实例(Python 2.0+)

#!/usr/bin/python

# coding=utf-8

dict = {'Google': 'www.google.com', 'Runoob': 'www.php.cn', 'taobao': 'www.taobao.com'}

print"字典值 : %s"%  dict.items()

# 遍历字典列表

forkey,values in  dict.items():

    printkey,values

以上实例输出结果为:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.php.cn')]

Google www.google.com

taobao www.taobao.com 

php www.php.cn

相关免费资料分享(点击即可免费观看~)

1、0基础入门python

http://www.makeru.com.cn/course/details/1804.html?s=96806

2、一堂课快速认识python数据分析

http://www.makeru.com.cn/live/5020_1655.html?s=96806

3、一节课快速认识人工智能必备语言:python

http://www.makeru.com.cn/live/5020_1635.html?s=96806

142244252 学习资料交流群,想要和志同道合的朋友一起学习,大家互相分享自己的学习资料和作品,欢迎感兴趣的朋友共同学习,共同进步,每天还会有免费的公开课程!!

相关文章

网友评论

      本文标题:python items()方法如何使用?

      本文链接:https://www.haomeiwen.com/subject/wxkbqhtx.html