Linux 拨号vps windows公众号手机端

python使用dict函数创建一个字典

lewis 6年前 (2019-03-21) 阅读数 9 #程序编程
文章标签 dict函数python

在python中使用dict()函数创建字典的方法

dict:dict()函数的作用是用于创建一个字典。

dict()函数语法:

class dict(**kwarg)

class dict(mapping, **kwarg)

class dict(iterable, **kwarg)

参数:

**kwargs:关键字。

mapping :元素的容器。

iterable:可迭代对象。

dict()函数使用方法:

>>> items = [('name','Gumby'),('age'.42)]

>>> d = dict(items)

>>> d

{'age':42,'name':'Gumby'}

>>> d = dict(name='Gumby','age'=42)

>>> d

{'age':42,'name':'Gumby'}

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门