Python dict() FunctionPython Functions


The dict() function is a built-in function that is used to create a dictionary.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print(dict(a='1', b='2', t='3'))
print(dict(name = "Tom", age = 23, country = "china"))

Output:

{'a': '1', 'b': '2', 't': '3'}
{'name': 'Tom', 'age': 23, 'country': 'china'}

Syntax

dict(keyword arguments)

Parameters

keyword arguments — just like many keyword arguments, separated by a comma: key = value, key = value …

Return Value

It returns a dictionary.

© 2021 Programtips.org, all rights reserved. Privacy Policy | Contact Us