Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python modify the value in the dictionary

Shulou Source: shulou.com Published: 2022-06-03 09:38:34 10月05日 Update

This article is about how python modifies the values in the dictionary. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. To modify the values in the dictionary, you can specify the dictionary name in turn, the key enclosed in square brackets and the new value related to the key.

> bullet = {'color':' green', 'points':' 5percent, 'bullet_x': 25,' bullet_y': 45} > bullet ['bullet_x'] = 10 > print (bullet) {' color': 'green',' points': '5percent,' bullet_x': 10, 'bullet_y': 45} >

2. For the information that is no longer needed in the dictionary, you can use the del statement to completely delete the corresponding key-value pairs.

> > bullet = {'color':' green', 'points':' 5percent, 'bullet_x': 25,' bullet_y': 45} > bullet ['bullet_x'] = 10 > > print (bullet) {' color': 'green',' points': '5percent,' bullet_x': 10, 'bullet_y': 45} > del bullet [' color'] > print (bullet) {'points':' 5percent, 'bullet_x': 10 'bullet_y': 45} > Thank you for your reading! This is the end of the article on "how to modify the value in the dictionary by python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Dictionary content more article good practical information name article square bracket look knowledge sentence reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft Docker MariaDB Shulou Technology