Wednesday, May 24, 2023

Python Dictionaries

# A dictionary is a collection of key:value pairs

# Keys are immutable objects like string, tuple and frozenset.

# Dictionary is ordered - i.e items of a dictinary always print in same order

# Dictionary is changeable - i.e we can add, remove and change items after its creation

# No duplicate key allowed.

# Dictinary item values can be of any type - i.e they support mixed data type

Python Dictionary Methods

Problem 1

  • How would you add a new key to this dict?
  • d = {
  • "name": "Johanth",
  • "language": "Python",
  • "state": "Telangana",
  • }
  • Key name is: age

Solution 1

  • 1) Using assignment operator
  • 2) Using update() method

Now in code

Tags: Python,Technology,

No comments:

Post a Comment