How to create and initialize dictionary with default value in Python

1 Answer

0 votes
default_value = 0

dic = dict.fromkeys(['python', 'php', 'java', 'c++'], default_value)

print(dic)



'''
run:

{'python': 0, 'php': 0, 'java': 0, 'c++': 0}

'''

 



answered Jun 30, 2022 by avibootz
...