DEV Community

Lakshmi Pritha Nadesan
Lakshmi Pritha Nadesan

Posted on

Day 18 - Object Oriented Programming

Object Oriented Programming(OOPS):

OOPS stands for Object-Oriented Programming System, which is a programming paradigm based on the concept of objects.

Class:

A blueprint or template for creating objects.
Class represent logical entities.

Object:

An object is representation of a class.
Objects represent real-world entities or real time entities.
Objects has states and behavior.

we cannot create object without class.But class can be present without objects.

Example with Bike:

The Bike class defines what a bike is and what it can do.
States like brand, color, and speed describe the bike.
Behavior like start, accelerate, and stop define actions a bike can perform.
Activa and Scooter are objects of the Bike class.
Each object represents a real bike with specific states (e.g., brand and color) and behaviors.

Example:

import calculator
#Object Creation
calc=calculator()
Enter fullscreen mode Exit fullscreen mode

Here calculator is a class and calc is a object.

Encapsulation:

Encapsulation is the bundling of data (attributes) and methods that operate on the data within one unit (class). It also restricts direct access to some components of the object.

Public, Protected, and Private Attributes:

Public:Accessible everywhere (self.name).

Protected:Accessible in the class and subclasses (self._name).

Private: Accessible only within the class (self.__name).

Example:

class company:
    def __research():
        pass
    def __give_salary():
        pass

co=company()
co.__research()

Enter fullscreen mode Exit fullscreen mode

__ is the special symbol called docker.

Python is multi paradigm Programming language.
Python supports
1.Object Oriented Programming
2.Functional programming
3.Modular Programming
4.Procedure oriented Programming

C# supports object oriented programming.
Java and JS supports object oriented programming and functional programming.

Interpreter, compiler and OS written by C language. That supports procedure oriented programming.

We can install the module using the following commend:

sudo apt install python3-modulename

Example for emoji module:

import emoji
result = emoji.emojize('Python is :thumbs_up:')
print(result)

# You can also reverse this:
result = emoji.demojize('Python is ๐Ÿ‘')
print(result)

Enter fullscreen mode Exit fullscreen mode
Python is ๐Ÿ‘
Python is :thumbs_up:
Enter fullscreen mode Exit fullscreen mode

Top comments (0)