Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add a new key value to the python dictionary

Shulou Source: shulou.com Published: 2022-06-03 09:41:01 10月31日 Update

This article will explain in detail how to add new key values to the python dictionary. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

Dictionaries are dynamic structures and new elements can be added at any time. For example, add x and y coordinates of bullet to dictionary. print (bullet) You can see the coordinates of the bullet in the dictionary.

Note>>> is not code, representing the command line format in the Python interpreter, prompting for input.

examples

>>> bullet['bullet_x']=25>>> bullet['bullet_y']=45>>> print(bullet){'color': 'green', 'points': '5', 'bullet_x': 25, 'bullet_y': 45}>>> About "how to add new key values in python dictionary" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Dictionaries articles coordinates bullets more good practical code representatives elements content dynamics commands examples articles formats knowledge structures interpreters references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MariaDB Shulou Technology vpn Shulou Tech Info