item是什么函数

右脚踩大鞋 1个月前 已收到2个回答 举报

收摊带走爱 4星

共回答了453个问题采纳率:97.2% 评论

是python items函数

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

语法

items()方法语法:

dict.items()

参数

NA。

返回值

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

实例

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

# !/usr/bin/python

# coding=utf-8

dict = {'Google': 'google.com', 'Runoob': 'runoob.com', 'taobao': 'taobao.com'}

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

# 遍历字典列表

for key, values in dict.items():

print key, values

以上实例输出结果为:

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

Google google.com

taobao taobao.com

Runoob runoob.com

11小时前

11

嘸莇尒莮亾 1星

共回答了169个问题 评论

itemgetter函数:

  operator.itemgetter函数

  原型:

  operator.itemgetter(item)

  operator.itemgetter(*items)

  Return a callable object that fetchesitemfrom its operand using the

operand’s__getitem__()method. If multiple items are specified, returns a tuple

of lookup values. For example:

  Afterf=itemgetter(2), the callf(r)returnsr[2].

  Afterg=itemgetter(2,5,3), the callg(r)returns(r[2],r[5],r[3]).

  operator.itemgetter函数返回的是一个函数,该函数返回指定序号的值,通过该函数作用到对象上才能获取值

9小时前

21
可能相似的问题

热门问题推荐

Copyright © 2024 微短问答 All rights reserved. 粤ICP备2021119249号 站务邮箱 service@wdace.com