How to create dictionary using dict() constructor in Python

2 Answers

0 votes
d = dict(name="Fox", age=52, profession="Programmer", salary=15890)

print(d)


'''
run:

{'profession': 'Programmer', 'name': 'Fox', 'age': 52, 'salary': 15890}

'''

 



answered Dec 9, 2018 by avibootz
0 votes
dic = dict([(1, 'python'), (2, 'c++'), (3, 'c'), (4, 'c#')])


print(dic)

for key, value in dic.items():
	print(key, ': ', value)




'''
run:

{1: 'python', 2: 'c++', 3: 'c', 4: 'c#'}
1 :  python
2 :  c++
3 :  c
4 :  c#

'''

 



answered Jan 12, 2021 by avibootz

Related questions

1 answer 138 views
1 answer 200 views
200 views asked Oct 17, 2020 by avibootz
1 answer 130 views
1 answer 94 views
3 answers 212 views
212 views asked Oct 7, 2019 by avibootz
...