Object Oriented Python
- Everything in python is object which is instance of some class
- Lets define a class
class Student:
pass
- Now to create an object which is also referred as instantiation
student = Student()
-
Refer Here for the Jupyter notebook added
-
We might want to create classes which have attributes and behaviour
- We need to understand two important terminologies
- Class
- Object
- When we define the attributes in python classes we can define the attributes at
- Class attribute
- object attributes or instance attribute
- When we define methods in python we have
- class methods
- object methods (instance methods)
- We need to understand two important terminologies
-
Class level attributes: Attributes at class level and are common across all the objects of the class
-
Instance level attributes
-
Initialization:
- If we want to assign object attributes at creation time, we need to use python’s special methods
__init__
- Refer Here for the creation of instance attributes
- If we want to assign object attributes at creation time, we need to use python’s special methods
-
Exercise: Create a car class and create two object ‘MarutiSwift’ and ‘Hyundai Creta’
-
Write print statement which prints the attribute with its memory location
-
Refer Here for the solution
-
Lets Try to Create a classes for Movies Ratings
- classes: Movie
- Rating:
- Review
-
Refer Here for the class structures created
-
Exercise: Using the Classes defined try to create an object representation for the Avengers movie Refer Here
-
Refer Here for the implementation