Python3 字典 keys() 方法

Python 3 教程 · 2019-02-06 16:27:25

描述

Python3 字典 keys() 方法返回一个可迭代对象,可以使用 list() 来转换为列表。

注意:Python2.x 是直接返回列表

语法

keys()方法语法:

dict.keys()

参数

  • NA。

返回值

返回一个迭代器。

实例

以下实例展示了 keys() 方法的使用方法:

>>> dict = {'Name': 'Codercto', 'Age': 7}
>>> dict.keys()
dict_keys(['Name', 'Age'])
>>> list(dict.keys())             # 转换为列表
['Name', 'Age']
>>> 

以上实例输出结果为:

字典所有的键为 : dict_keys(['Age', 'Name'])

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

The Probabilistic Method

The Probabilistic Method

Noga Alon、Joel H. Spencer / Wiley-Interscience / 2008-8-11 / USD 137.00

Praise for the Second Edition : "Serious researchers in combinatorics or algorithm design will wish to read the book in its entirety...the book may also be enjoyed on a lighter level since the diffe......一起来看看 《The Probabilistic Method》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码