Skip to main content

What Is Encapsulation In Python?|What is Python?|What Is Encapsulation?| How to declare and access data?|What Is Encapsulation In Python?


What Is Encapsulation In Python?

 Description:

WELCOME TO OUR NEW INFORMATIVE POST, WHERE WE LEARN TECHNICAL INFORMATION AND SOLVE USUAL ERRORS & PROBLEMS.

This tutorial will discover what Python is and the Python Encapsulation idea. Then, we fix some run time issues in coding for deep understanding.

Before we get late, let's get started

What is Python:

Python is the most utilized language in the history of programming languages. It takes part in various types of programming.

Such as website & software building, data analysis, game developing concepts, and automated work.

For this reason, Python is known as a general-purpose language, with the approach of Python, anyone may create a variety of programs.   

What Is Encapsulation?

In C++ & Java, one of the essential components of object-oriented programming is Encapsulation.

It implies grouping data elements and operations inside of one class.

Encapsulation aims to ensure that "sensitive" data is hidden from users.

 
How to declare and access data?

 

  • Class variables & attributes are declared in private 
  • To access the private data, use Get & Set method to update the private members of a variable.

 We are providing some coding examples which give a broad experience with Encapsulation for a pleasant result with article content.

Program is based on a company profit, where the class is a company , the method is private and the variable is profit

class Company {

  private:

    int profit;

 

  public:

    void setProfit(int p) {

      profit = p;

    }

    int getProfit() {

      return profit;

    }

};

 

int main() {

  Company myObj;

  myObj.setProfit(50000);

  cout << myObj.getProfit()<<"= profit of month";

  return 0;

}

Output:

50000 = profit of mouth


In the above article, we understand what’s Python & Encapsulation, now we came on our main topic, what is Encapsulation in python.

What Is Encapsulation In Python?



Python encapsulation is an important characteristic of object-oriented programming (OOP). 

 Its  main work is to hide "sensitive "information from public members. It defines the concept of data covering and the methods that work on data within a separate unit.

 Every object-oriented programming language will use the same concept of Encapsulation.

  • JAVA 
  • C++
  • Python 

These are the major object-oriented programming languages that use the concepts of Encapsulation.   

Example code:

 

# Creating a Base class

class Base:

    def __init__(self):

        self.a = "Python program"

        self.__c = " Python WEB"


# Creating a derived class

class Derived(Base):

    def __init__(self):


        # Calling constructor of

        # Base class

        Base.__init__(self)

        print("Calling private member of base class: ")

        print(self.__c)


obj1 = Base()

print(obj1.a)

 
Output:

Python program

Conclusion:

In this article, we will learn new concepts of Python and Encapsulation.

Then, we perform a small task of Encapsulation program, which help's to understand their complex concept.

Last, we discussed and coded our main module, what is Encapsulation in Python?

If you want to learn the latest technical programming, keep reading our articles. 

Have a good day to you.

Comments

Popular posts from this blog

How to select an appealing Rug for the living room: some common leads

  How to select an appealing Rug for the living room: some common leads Every household person who has a wish to decorate their dream house according to their preferences tries their best to make it as beautiful as they dream it.  While decorating, there is a community of people who focus on their living room because it is the leading room which represents the status of the whole house and its holders.   So it is obvious that every single showpiece and furniture represents the feels of the living room, here an appealing Rug adds some value to the living room. But lots of people are not mentally satisfied by choosing a Rug because this specific product comes in varieties of sizes, materials, designs, and colors. Today we are going to gain some basic leads to choose a Rug according to our room interior design.   If you already know about Rugs and are searching for a trusted site to buy, you can visit our online store RugKnots.com where you will find incredible designs...

Uniswap Revolution of Cryptocurrency; Trading with Decentralised Exchanges:

  Uniswap Revolution of Cryptocurrency; Trading with Decentralised Exchanges: A cryptocurrency exchange is an online platform where users can buy, sell, or exchange cryptocurrencies. These exchanges enable transaction connections between buyers and sellers directly and could provide numerous features and tools to help in trade. Uniswap Intro: A recognized platform that provides exchange deals, or top cryptocurrencies to trade, is used by Uniswap , a decentralized cryptocurrency exchange, to execute trades. This open-source project falls within the DeFi (Decentralised Finance) product category since it makes use of contract technology to support trading. A decentralized exchange contains an unassailable security framework but it kind a complex UI(User Interface). According to a Web channel : Uniswap is a leading decentralised crypto exchange that runs on the Ethereum blockchain . This means you can buy any cryptocurrency with Ethereum currency. What is the mechanism of blockchain? B...

What Is LARAVEL|What Is Laravel, and how do you get started with it| What is XAMPP?|What is the Composer?

  What Is LARAVEL, and how do you get started with it Description: In today's tutorial, we'll learn what Laravel is, how to get started with it, and some installation and file creation commands. For a better understanding, we will discuss Laravel in detail and discuss the software that makes Laravel run smoothly. But for now, our primary focus is on what LARAVEL is and how you get started with it. Let's start our journey: What Is Laravel, and how do you get started with it: Laravel  is an open-source framework for  PHP  language. It is a framework that is easy to understand and user-friendly framework. Moreover, the project's development follows a modern view controller design pattern.   Laravel recycles existing components from other frameworks, which helps develop a web application. To start your development journey with  Laravel , you need to follow these steps: First, install  XAMPP  in your operating system Instal...