python中dict函数_dict()函数以及Python中的示例

本文详细介绍了Python中使用dict()函数创建字典的方法。dict()函数作为Python的库函数,可以接受一组带有关键字和值的参数,从而创建出字典。文章通过实例展示了如何使用dict()函数,并解释了其语法和参数。

python中dict函数

Python dict()函数 (Python dict() function)

dict() function is a library function, it is used to create a dictionary with keywords( Ids) and values (s), it accepts a set of values with keywords, values and returns a dictionary.

dict()函数是一个库函数,用于创建带有关键字(Ids)和值(s)的字典,它接受带有关键字,值的一组值并返回字典。

Syntax:

句法:

    dict(keyword1=value1, keyword2=value2, ...)

Parameter(s): keyword1=value1, keyword2=value2, ... – a set of keywords and values to create a dictionary.

参数: keyword1 = value1,keyword2 = value2,... –用于创建字典的一组关键字和值。

Return value: dict – returns dictionary.

返回值: dict –返回字典。

Example:

例:

    Input:
    # creating dictionary 
    std_info = dict(name = "Amit shukla", age = 21, course = "B.Tect (CS)")

    # printing the value of dictionary 
    print("std_info:", std_info)
    
    Output:
    std_info: {'course': 'B.Tect (CS)', 'age': 21, 'name': 'Amit shukla'}

Python code to create a dictionary

用Python代码创建字典

# python code to demonstrate example of 
# dict() number

# creating dictionary 
std_info = dict(name = "Amit shukla", age = 21, course = "B.Tect (CS)")

# printing type 
print("type of std_info: ", type(std_info))

# printing the value of dictionary 
print("std_info:", std_info)

Output

输出量

type of std_info:  <class 'dict'>
std_info: {'course': 'B.Tect (CS)', 'age': 21, 'name': 'Amit shukla'}


翻译自: https://www.includehelp.com/python/dict-function-with-example.aspx

python中dict函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值