0% found this document useful (0 votes)
4 views1 page

Python Dictionaries and Classes Explained

The document explains how to access, add, and update values in Python dictionaries, providing examples of printing and modifying a 'person' dictionary. It also introduces classes as user-defined blueprints containing variables and methods, highlighting the distinction between functions and methods. Additionally, it describes how to call methods using both the class name and instance name.

Uploaded by

gauravbr
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Python Dictionaries and Classes Explained

The document explains how to access, add, and update values in Python dictionaries, providing examples of printing and modifying a 'person' dictionary. It also introduces classes as user-defined blueprints containing variables and methods, highlighting the distinction between functions and methods. Additionally, it describes how to call methods using both the class name and instance name.

Uploaded by

gauravbr
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

DICTIONARIES

Accessing Values
print(person["name"]) # Rahul
print(person["age"]) # 25

Adding / Updating Items


person["email"] = "rahul@[Link]" # add new key
person["age"] = 26 # update existing key

print(person)
# {'name': 'Rahul', 'age': 26, 'city': 'Delhi', 'email': 'rahul@[Link]'}

NOTE - double quotes inside double quotes in the f-string.


Python gets confused where the string starts/ends.
print(f"Car model: {[Link]('model')}")

CLASSES
It is user defined blueprint or prototype
class contains variable and methods. the same variable and method are also
available in the object because they
are created inside the instances

NOTE - The diff bw function and method. A function written inside a class is called
method
Generally method is called by the following two ways
1. [Link]()
[Link]()

You might also like