What is a class? Why is it being used in Object-oriented programming languages? What is actually Object-oriented programming?
Do you play games? Yes, a game like Super Mario, Pacman, breakout game, snake game, etc. These different types of games are the part of one big blueprint named as "GAME" :). So there is something which creates a blueprint of various types of games and keeps them together in a player like video games device (eg, Play Station, etc).
As I explained in above example, Class is just a blueprint which contains stuff like properties, variables, member functions and all. A class definition starts with class keyword followed by class name.
Objects can be anything. An object is just an instance of the class which holds the data variables declared in class and the functions work on these class objects.
class SampleClass: def function(self): print("Sample function inside a class.") classReference = SampleClass() classReference.function()
self parameter is a reference to the class itself and is used to access variables that belong to the class. classReference is the object of SampleClass() and you can access the functions or variables of the class using . dot operator.
Unlock learning opportunities with our expert-led coding courses.
Real-time doubt solving in a live online coding class is also available in the course
that will help you to stay connected with an experts while learning.