python之items()的用法
2022年5月5日,今天学习算法时,看到了一个之前未见过的函数,记录一下这个函数的用法。Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。代码如下:d = {'one':1, 'two':2, 'three':3}print(d.items())print(type(d.items()))代码执行结果:代码样例:# 当两个参数时for key
·
2022年5月5日,今天学习算法时,看到了一个之前未见过的函数,记录一下这个函数的用法。
Python
字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。
代码如下:
d = {'one':1, 'two':2, 'three':3}
print(d.items())
print(type(d.items()))
代码执行结果:
代码样例:
# 当两个参数时
for key, value in d.items():
print(key+":"+str(value))
# 当一个参数时
for i in d.items():
print(i)
代码结果如下:
更多推荐
已为社区贡献1条内容
所有评论(0)