---
title: What are decorators in Python?
description: What are decorators in Python?
---

[Skip to content](https://help.datasciencedojo.com/migration/what-are-decorators-in-python#main-content)

English

Show submenu for translations

[Customer portal](https://help.datasciencedojo.com/tickets-view?hsLang=en)

![DSD main logo.png\]](https://help.datasciencedojo.com/hs-fs/hubfs/DSD%20main%20logo.png?height=40&name=DSD%20main%20logo.png)

- [Default HubSpot Blog](https://help.datasciencedojo.com/blog)

Open main navigation

Close main navigation

- [Default HubSpot Blog](https://help.datasciencedojo.com/blog)
- English
  
  Show submenu for translations
- [Customer portal](https://help.datasciencedojo.com/tickets-view)
- Go to datasciencedojo.com

 Go to datasciencedojo.com

 How can we help?

- There are no suggestions because the search field is empty.

1. [Help Center](https://help.datasciencedojo.com/migration?hsLang=en)
2. [Python Programming](https://help.datasciencedojo.com/migration/python-programming?hsLang=en)

# What are decorators in Python?

Decorators in Python are essentially functions that add functionality to an existing function in Python without changing the structure of the function itself. They are represented the @decorator\_name in Python and are called in a bottom-up fashion. For example:

 

\# decorator function to convert to lowercase

def lowercase\_decorator(function):

def wrapper():

func = function()

string\_lowercase = func.lower()

return string\_lowercase

return wrapper

\# decorator function to split words

def splitter\_decorator(function):

def wrapper():

func = function()

string\_split = func.split()

return string\_split

return wrapper

@splitter\_decorator # this is executed next

@lowercase\_decorator # this is executed first

def hello():

return 'Hello World'

hello() # output =\> \[ 'hello' , 'world' \]

The beauty of the decorators lies in the fact that besides adding functionality to the output of the method, they can even accept arguments for functions and can further modify those arguments before passing it to the function itself. The inner nested function, i.e. 'wrapper' function, plays a significant role here. It is implemented to enforce encapsulation and thus, keep itself hidden from the global scope.

 

\# decorator function to capitalize names

def names\_decorator(function):

def wrapper(arg1, arg2):

arg1 = arg1.capitalize()

arg2 = arg2.capitalize()

string\_hello = function(arg1, arg2)

return string\_hello

return wrapper

@names\_decorator

def say\_hello(name1, name2):

return 'Hello ' + name1 + '! Hello ' + name2 + '!'

say\_hello('sara', 'ansh') # output =\> 'Hello Sara! Hello Ansh!'

- [Data Science Bootcamp](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#main-content)

    - [Certificate](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#certificate)
    - [Logistics](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#logistics)
    - [Curriculum](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#curriculum)
    - [Target Audience](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#target-audience)
    - [Talk to an Advisor](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#talk-to-an-advisor)
    - [Prerequisites](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#prerequisites)
    - [Pricing](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#pricing)
    - [Policies](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#policies)
- [Large Language Models Bootcamp](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#main-content)

    - [Logistics](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#logistics)
    - [Curriculum](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#curriculum)
    - [Certificate](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#certificate)
    - [Prerequisites](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#prerequisites)
    - [Eligibility](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#eligibility)
    - [Talk to an advisor](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#talk-to-an-advisor)
    - [Pricing](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#pricing)
    - [Delivery](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#delivery)
    - [Program Overview](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#program-overview)
    - [Policies](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#policies)
    - [Registration](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#registration)
- [Agentic AI Bootcamp](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#main-content)

    - [Prerequisites](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#prerequisites)
    - [Logistics](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#logistics)
    - [Curriculum](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#curriculum)
    - [Program Overview](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#program-overview)
    - [Pricing](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#pricing)
    - [Preparatory Material](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#preparatory-material)
    - [Policies](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#policies)
    - [Talk to an Advisor](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#talk-to-an-advisor)
    - [Registration](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#registration)
- [Registration](https://help.datasciencedojo.com/migration/registration?hsLang=en#main-content)

    - [Payment Methods](https://help.datasciencedojo.com/migration/registration?hsLang=en#payment-methods)
    - [Free Certificate](https://help.datasciencedojo.com/migration/registration?hsLang=en#free-certificate)
    - [Tuition Benefits](https://help.datasciencedojo.com/migration/registration?hsLang=en#tuition-benefits)
- [Pricing](https://help.datasciencedojo.com/migration/pricing?hsLang=en)
- [Community](https://help.datasciencedojo.com/migration/community?hsLang=en#main-content)

    - [FODAI 2025 - Sept Edition](https://help.datasciencedojo.com/migration/community?hsLang=en#fodai-2025-sept-edition)
    - [FODAI 2026](https://help.datasciencedojo.com/migration/community?hsLang=en#fodai-2026)
- [Python Programming](https://help.datasciencedojo.com/migration/python-programming?hsLang=en)
- [Platform Related Issues](https://help.datasciencedojo.com/migration/platform-related-issues?hsLang=en#main-content)

    - [Community](https://help.datasciencedojo.com/migration/platform-related-issues?hsLang=en#community)
- [Bootcamps](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#main-content)

    - [Formats and Delivery](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#formats-and-delivery)
    - [Certificates](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#certificates)
    - [Policies](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#policies)
    - [Session Access](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#session-access)
    - [Benefits](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#benefits)
    - [Exercises](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#exercises)
    - [Tuition Benefits](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#tuition-benefits)
    - [Logistics](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#logistics)
    - [Testimonials](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#testimonials)
- [Homework and Notebooks](https://help.datasciencedojo.com/migration/homework-and-notebooks?hsLang=en#main-content)

    - [Personal Assigments](https://help.datasciencedojo.com/migration/homework-and-notebooks?hsLang=en#personal-assigments)
- [Free Courses](https://help.datasciencedojo.com/migration/free-courses?hsLang=en)
- [Data Science for Business](https://help.datasciencedojo.com/migration/data-science-for-business?hsLang=en#main-content)

    - [Program Overview](https://help.datasciencedojo.com/migration/data-science-for-business?hsLang=en#program-overview)
- [Practicum](https://help.datasciencedojo.com/migration/practicum?hsLang=en#main-content)

    - [Logistics](https://help.datasciencedojo.com/migration/practicum?hsLang=en#logistics)
    - [Program Overview](https://help.datasciencedojo.com/migration/practicum?hsLang=en#program-overview)
- [Blog](https://help.datasciencedojo.com/migration/blog?hsLang=en#main-content)

    - [Content Collaboration](https://help.datasciencedojo.com/migration/blog?hsLang=en#content-collaboration)
    - [Guest Posts](https://help.datasciencedojo.com/migration/blog?hsLang=en#guest-posts)
    - [Link Exchanges/Insertions](https://help.datasciencedojo.com/migration/blog?hsLang=en#link-exchanges-insertions)
- [Employment Assistance](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#main-content)

    - [Resumes](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#resumes)
    - [Internships](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#internships)
    - [Profile Shortlisting](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#profile-shortlisting)
    - [Career Paths](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#career-paths)
    - [Applying for Mentor](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#applying-for-mentor)
- [Machine Learning](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#main-content)

    - [Unsupervised](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#unsupervised)
    - [Supervised](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#supervised)
    - [Statistics](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#statistics)
    - [Deep Learning](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#deep-learning)
    - [Timeseries](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#timeseries)
- [Data Analysis](https://help.datasciencedojo.com/migration/data-analysis?hsLang=en)
- [R Language](https://help.datasciencedojo.com/migration/r-language?hsLang=en)
- [Python for Data Science](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#main-content)

    - [Prerequisites](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#prerequisites)
    - [Pricing](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#pricing)
    - [Curriculum](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#curriculum)
    - [Program Overview](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#program-overview)
- [SQL](https://help.datasciencedojo.com/migration/sql?hsLang=en)
- [Introduction to Power BI](https://help.datasciencedojo.com/migration/introduction-to-power-bi?hsLang=en)
- [Power BI](https://help.datasciencedojo.com/migration/power-bi?hsLang=en)
- [Programming and Tools](https://help.datasciencedojo.com/migration/programming-and-tools?hsLang=en#main-content)

    - [SQL](https://help.datasciencedojo.com/migration/programming-and-tools?hsLang=en#sql)
- [Partnerships](https://help.datasciencedojo.com/migration/partnerships?hsLang=en)

- [Default HubSpot Blog](https://help.datasciencedojo.com/blog)

[![Chill listening crop-3](https://help.datasciencedojo.com/hs-fs/hubfs/DSD%20main%20logo.png?width=95&height=24&name=DSD%20main%20logo.png "Chill listening crop-3")](https://datasciencedojo.com)

<https://www.linkedin.com/company/data-science-dojo/> <https://twitter.com/DataScienceDojo> <https://www.youtube.com/c/Datasciencedojo> <https://instagram.com/data_science_dojo?igshid=YmMyMTA2M2Y=> <https://www.facebook.com/datasciencedojo>

Copyright © 2026, Data Science Dojo