Aditi Pateriya
4 min readJun 24, 2021

--

class ClassName:
# Statement-1
.
.
.
# Statement-N
#defining a class called Animals.
class Animals:
pass
image by Daksh-Deepak\medium
class Animals:
a1 = "cat"
a2 = "dog"
#A sample fucntion in the class
def func(self):
print("This is a ", self.a1)
print("This ia a", self.a2)#Object instantiationobj = Animals()#Accessing class attributes and method through objects
print(obj.a1)
obj.func()
class Student:
def __init__(self, name, age):
self.name = name
self.age = age

p1 = Student("Aditi", 20)
print(p1.name)
print(p1.age)
Output:
Aditi
20
class Person:
def __init__(myobject, name, age):
myobject.name = name
myobject.age = age

def myfunc(abc):
print("Hello my name is " + abc.name)

p1 = Person("Amy", 40)
p1.myfunc()
#Python program to illustrate closuresdef outerFunction(text)
text = text
def innerFunction():
print(text)
#we are returning functions without parenthesis
return innerFunction
if __name__ == '__main__':
myFunction = outerFunction('hello!')
myFunction()
The function innerFunction has its scope only inside the outerFunction. But with the use of closures, we can easily extend its scope to invoke a function outside its scope.
@ABC_decorator
def hello_decorator():
print("ABC")

'''Above code is equivalent to -

def hello_decorator():
print("ABC")
pic by TechBeamers
_get__(self, obj, type=None) -> object
__set__(self, obj, value) -> None
__delete__(self, obj) -> None
__set_name__(self, owner, name)

--

--

Aditi Pateriya

A curious learner , an engineer by profession , exploring the world through writings