Python Tutorial 35 --- "Classes & Objects (OOPS)"
Python Tutorial 35 --- "Classes & Objects (OOPS)"
Python is a powerful programming language that supports the object-oriented programming paradigm. In object-oriented programming, the program splits into self-contained objects. Each object is representing a different part of the application which can communicate among themselves. We will be discussing classes and objects in more detail in the next tutorial i.e, Creating Our First Class In Python. The primary focus of this tutorial is to give you the understanding of Object-Oriented Programming or in short form OOP. A programming technique that requires the use of objects and classes is known as OOP. Object-Oriented Programming is based on the principle of writing reusable code that can be accessed multiple times by the user.
What is Python Class And Object?
A class is a collection of objects, and an object is defined as an instance of class possessing attributes. The object is an entity that has state and behavior. A class has all the similar attributes, like if we have a class students, then it will only consist of students related data, such as subjects, names, attendance ratio, etc.
Along with classes and objects, you will learn many new terminologies related to OOP in further tutorials. Some of these terminologies are:
- Instances
- Constructor
- Methods
- Abstraction
- Inheritance
By using oop, we can divide our code into many sections known as classes. Each class holds a distinct purpose or usage. For example, if we have created a class named "Books" then all the attributes it possesses should be related to books such as the number of pages, publishing date or price, etc.
There is no limit to the number of classes we can create in a program. Also, one class can be easily accessible by another, and we can also restrict the access of a class so other classes can not use its functions. This concept comes in handy while working on bigger projects. All the employees are given separate tasks to work on the classes they have been assigned. And after they are done with their contribution, the classes can be combined as a whole to form a complete project. So, now you can understand that to become a successful programmer, you must master the concept of OOP.
Object-oriented vs. Procedure-oriented Programming
Index | Object-oriented programming | Procedure Oriented Programming |
1 | Object-oriented programming is the problem-solving approach. The computation is done by using objects. | It is Structure oriented. Procedural programming uses a list of instructions. It performs the computation step by step. |
2 | OOP makes development and maintenance easier. | When the project becomes lengthy, it is not easy to maintain the code. |
3 | OOP provides a proper way for data hiding. It is more secure than procedural programming. You cannot access private data from anywhere. | Procedural programming does not provide any proper way for data binding, so it is less secure. In Procedural programming, we can access the private data. |
4 | Program is divided into objects | The program is divided into functions. |
In this tutorial, we have discussed the basics of object-oriented programming. In the next tutorial Creating Our First Class in Python, we will start implementing the OOP concepts.
CODE ---
# Classes & Objects
# Class - is a template
# Object - instance of a class
Comments
Post a Comment