How to add a new key value pair to a dictionary in Python

2 Answers

0 votes
dic = {
    "name": "Tom",
    "age": 52,
    "language": "python", 
    "company":  "google"}
    
dic.update({"start": 2001})

print(dic)





'''
run:

{'name': 'Tom', 'age': 52, 'language': 'python', 'company': 'google', 'start': 2001}

'''

 



answered Mar 11, 2023 by avibootz
0 votes
dic = {
    "name": "Tom",
    "age": 52,
    "language": "python", 
    "company":  "google"}
     
dic["start"] = 2001
 
print(dic)
 
 
 
 
 
'''
run:
 
{'name': 'Tom', 'age': 52, 'language': 'python', 'company': 'google', 'start': 2001}
 
'''

 



answered Mar 11, 2023 by avibootz

Related questions

2 answers 188 views
2 answers 131 views
1 answer 149 views
2 answers 175 views
1 answer 132 views
...