Learn Python like a Professional! Take You from 0 to Hero
In this Python lecture, we will learn about the Python Decorators.
Decorators in Python
"Decorator is a function that takes another function as argument adds some kind of functionality and then returns another function."
Decorators in Python
Let's see some example-
def decorator_function(original_function): def wrapper_function(): print('Hi') original_function() return wrapper_function
@decorator_function def first_msg(): print("Welcome back to python ninja bootcamp")
first_msg()
>>Hi
Welcome back to python ninja bootcamp
Welcome back to python ninja bootcamp
@decorator_function
def second_msg():
print("In this lecture will cover decorators")
def second_msg():
print("In this lecture will cover decorators")
first_msg()
>>Hi
In this lecture will cover decorators
In this lecture will cover decorators
def decorator_function(original_function): def wrapper_function(a,b): original_function(a,b) print("Code Ends Here") return wrapper_function
@decorator_function def sum_function(a,b): print("Sum of a and b=",a+b)
sum_function(2,5)
>>Sum of a and b= 7
Code Ends Here
Code Ends Here
In the next Blog, we will discuss Map()
https://sngurukuls247.blogspot.com/2018/12/python-ninja-bootcamp-32-map.html
......................................................................................................................................
Instagram-
https://www.instagram.com/python.india/
View the Jupyter Notebook for this lecture
Download the Jupyter Notebook for this lecture
https://sngurukuls247.blogspot.com/2018/12/python-ninja-bootcamp-32-map.html
......................................................................................................................................
Follow the link below to access Free Python Lectures-
https://www.youtube.com/channel/UCENc9qI7_r8KMf6-_1R1xnwInstagram-
https://www.instagram.com/python.india/
View the Jupyter Notebook for this lecture
Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com
No comments:
Post a Comment