Lokang 

Python and MySQL

Encapsulation

In object-oriented programming (OOP), encapsulation is a concept that refers to the bundling of data and functions that operate on that data within a single unit, or object.

Encapsulation allows you to hide the implementation details of a class (the data and functions it contains) from other parts of your program, and only expose a simplified interface (the class's methods) to the outside world. This helps to reduce the complexity of the program and make it more modular and maintainable.

In Python, you can use the class keyword to define a new class, and the self keyword to refer to the instance of the class within its own methods. The methods of a class are defined using the def keyword, just like regular functions, but they take the self parameter as their first argument.

Here is an example of a class in Python that demonstrates encapsulation:

class BankAccount:
   def __init__(self, balance):
       self.balance = balance
   def deposit(self, amount):
       self.balance += amount
   def withdraw(self, amount):
       if self.balance >= amount:
           self.balance -= amount
       else:
           print("Insufficient funds")
account = BankAccount(100)
account.deposit(50)
account.withdraw(75)
print(account.balance)  # Output: 75

In this example, the BankAccount class has three methods: __init__(), deposit(), and withdraw(). The __init__() method is a special method in Python that is called when an instance of the class is created, and it is used to initialize the instance's attributes (in this case, the balance attribute).

The deposit() and withdraw() methods allow the user to deposit or withdraw money from the bank