What is encapsulation in Python?
What is encapsulation in Python?
What is encapsulation in Python?
solveurit24@gmail.com Changed status to publish February 13, 2025
Encapsulation is the practice of hiding data and methods within a class, controlling access through public interfaces.
class Car:
def __init__(self, speed):
self.__speed = speed
def get_speed(self):
return self.__speed
def set_speed(self, new_speed):
self.__speed = new_speed
car = Car(100)
print(car.get_speed()) # Output: 100
car.set_speed(150)
print(car.get_speed()) # Output: 150solveurit24@gmail.com Changed status to publish February 13, 2025