Ad Code

Responsive Advertisement

Dictionary in Python Class 11 Notes | Tuples and Dictionaries

  

What is Dictionary

  • Dictionaries are unordered collection of items falls under mapping.
  • Stores data in form of key:value pair called item.
  • Key is separated from its value by colon ‘:’ and items are separated by comma.
  • All items of dictionaries are enclosed in curly bracket ‘{}’.
  • The keys in the dictionary must be unique and should be of immutable data type.
  • The value can be repeated and of any data type.

Creating a Dictionary


Accessing items in a Dictionary

  • Items of dictionary are accessed using keys.
  • Each key of dictionary serve as index and maps to a value.
  • If key is not present in dictionary, then we get KeyError.

Examples

Dictionary is Mutable

Yes, Dictionary is Mutable as its content can be changed after it has been created.

Adding a new item in Dictionary

Modifying an existing Item in Dictionary

Traversing a dictionary

Dictionary methods and built in functions




Post a Comment

0 Comments