How to change dictionary values in Python

2 Answers

0 votes
dict = {234 : 'python', 8762: 'java', 3: 'php', 18: 'c', 200 : 'c++'}
 
print(dict)

dict.update({8762: 'c#', 3: 'javascript'})

print(dict)



'''
run:

{234: 'python', 8762: 'java', 3: 'php', 18: 'c', 200: 'c++'}
{234: 'python', 8762: 'c#', 3: 'javascript', 18: 'c', 200: 'c++'}

'''

 



answered Apr 11, 2021 by avibootz
0 votes
dict = {234 : 'python', 8762: 'java', 3: 'php', 18: 'c', 200 : 'c++'}
 
print(dict)

dict = ({**dict,  8762: 'c#', 3: 'javascript'})

print(dict)



'''
run:

{234: 'python', 8762: 'java', 3: 'php', 18: 'c', 200: 'c++'}
{234: 'python', 8762: 'c#', 3: 'javascript', 18: 'c', 200: 'c++'}

'''

 



answered Apr 11, 2021 by avibootz
...