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函数
本文详细介绍了Python中使用dict()函数创建字典的方法。dict()函数作为Python的库函数,可以接受一组带有关键字和值的参数,从而创建出字典。文章通过实例展示了如何使用dict()函数,并解释了其语法和参数。
函数以及Python中的示例&spm=1001.2101.3001.5002&articleId=107803714&d=1&t=3&u=57e4277a6149458e8061e60383eb2006)
3965

被折叠的 条评论
为什么被折叠?



