September 27

Dictionary

A dictionary, in python, is a built-in data type that represents an unordered collection of key-value pairs. It is also known as an associative array or a hash table in other programming languages. Dictionaries are enclosed in curly braces { } and consist of comma-separated key-value pairs.

Key Features of Python Dictionaries:

  1. Mutable: Dictionaries are mutable, which means their contents can be modified after creation. You can add, update, or delete key-value pairs.
  2. Unordered: Dictionaries are unordered, meaning the order of the key-value pairs is not guaranteed. In other words, the elements are not stored in a specific sequence.
  3. Unique Keys: Dictionary keys must be unique. If you assign a new value to an existing key, it will update the corresponding value. If you add a new key-value pair with an existing key, it will overwrite the existing value.
  4. Flexible Key and Value Types: Dictionary keys can be of any immutable type, such as strings, numbers, or tuples. Values can be of any type, including built-in types, custom objects, or even other dictionaries.

Deleting Items From Dictionaries
Dictionary has two method to delete/clear the data

      • del, will delete individual item from dictionary
      • clear , will clear all the data and give you a empty dictionary