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函数