Encapsulation and Abstraction in Python
# Encapsulation ---> Bundling data and methods
# Abstraction ---> Hiding the complexity from user
class Person:
instances = 0
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
Person.instances += 1
@classmethod
def inst_no(cls):
print(f"{cls.__name__} class has {cls.instances} instances.")
p1 = Person("Adrika", "Bhadauria")
p2 = Person("Anika", "Singh")
Person.inst_no()
l = [1,2,3,4,5]
print(len(l))
Post a Comment