Test your Programming knowledge

50% users failed to get the best score. It's your turn to test now.
Questions curated by the expert mentors at codzify.com

Start Quiz


Python Classes and Objects - Codzify.com

1 min 57 sec read

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).

What is the Class ?

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.

What are Objects:-

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.

The syntax for creating Objects in Python

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.

Recommended Articles

Did you found this article helpful?

Try to execute what you have learnt

Easy to use online data structure compiler where you can execute the programs in your favourite programming language.
(C, C++, Python)

Open Compiler

HTML, CSS and Javascript Real time Web Editor

Execute your HTML, CSS and javascript code in real time with the web editor
(HTML, CSS, Bootstrap, Javascript)

Open Web Editor