+ 2

Decorators in python.

I made the decorators course in solo learn but I don't have pro, so I couldn't try it. I understand nothing! Can someone explain me decorators, higher order functions and this functions in functions AND give me examples why and how to use? This course I so short and badly to understand!!!

21st Aug 2025, 7:40 AM
Jakob
Jakob - avatar
21 Respostas
+ 5
you don't need a pro account to write decorator functions. there are external sources that can help you learn about decorators. https://realpython.com/primer-on-JUMP_LINK__&&__python__&&__JUMP_LINK-decorators/ yes, i agree, the courses have become less and less educational with each revision. not enough explanation and examples, all for the sake of keeping the lesson format consistent and 'cute'. a case of form over function. anyway, decorators are higher-order functions. they accept functions as arguments. they call the function internally and perform additional operations on the result. the @decorator is just a convenient syntax sugar. the lesson have this example: def uppercase(func): def wrapper(): orig_message = func() modified_message = orig_message.upper() return modified_message return wrapper @uppercase def greet(): return "Welcome!" # Using the decorated function print(greet()) if you comment out @uppercase, you could use uppercase like: print(uppercase(greet)())
21st Aug 2025, 8:27 AM
Bob_Li
Bob_Li - avatar
+ 3
Thank you! This article is so much better than the sololearn course!
21st Aug 2025, 9:30 AM
Jakob
Jakob - avatar
+ 2
Moi non
23rd Aug 2025, 6:59 AM
Jakob
Jakob - avatar
+ 1
why this ⬇️? uppercase(greet)() because uppercase returns another function -> wrapper. you have to call that to get the final result. uppercase(greet)() is the same as wrapper(). or maybe you can assign the returned function to a variable: decorated_function = uppercase(greet) print(decorated_function()) it's awkward, thus the @uppercase decorator syntax. then you just have to use greet().
21st Aug 2025, 9:12 AM
Bob_Li
Bob_Li - avatar
+ 1
Can you give an example for what it is really useful?
21st Aug 2025, 12:56 PM
Jakob
Jakob - avatar
+ 1
the RealPython link have a few examples at the end. i think it's commonly used in Flask, class decorators, lru cache, etc...
21st Aug 2025, 1:11 PM
Bob_Li
Bob_Li - avatar
+ 1
But RealPython isn't free
21st Aug 2025, 1:51 PM
Jakob
Jakob - avatar
+ 1
some articles are free.
21st Aug 2025, 1:54 PM
Bob_Li
Bob_Li - avatar
+ 1
Ok
21st Aug 2025, 1:58 PM
Jakob
Jakob - avatar
+ 1
This is not the right place! But why do you don't start a course if you are new?
22nd Aug 2025, 6:25 AM
Jakob
Jakob - avatar
+ 1
Qui est français ici
23rd Aug 2025, 6:42 AM
Aziz Bara
Aziz Bara - avatar
+ 1
Vous comprenez français non
23rd Aug 2025, 7:08 AM
Aziz Bara
Aziz Bara - avatar
+ 1
Je comprends un peu
23rd Aug 2025, 7:14 AM
Jakob
Jakob - avatar
+ 1
Là c'est bien tu est unpeu doué en développement Web non ont peut échanger les contacts whatsapp pour s'entraîner
23rd Aug 2025, 8:35 AM
Aziz Bara
Aziz Bara - avatar
+ 1
Tu pourrais aussi simplement m'écrire via sololearn. Mais je ne suis pas vraiment doué pour le développement web.
23rd Aug 2025, 8:46 AM
Jakob
Jakob - avatar
+ 1
Abon vraiment
23rd Aug 2025, 9:49 AM
Aziz Bara
Aziz Bara - avatar
+ 1
Je ne comprends pas.
23rd Aug 2025, 9:52 AM
Jakob
Jakob - avatar
+ 1
Non ça va OK mais tu n'es doué à quelque part
27th Aug 2025, 1:18 PM
Aziz Bara
Aziz Bara - avatar
0
Abeg I need help
22nd Aug 2025, 5:59 AM
Wisdom Emmanuel
Wisdom Emmanuel - avatar
0
I am just new, I don't know anything
22nd Aug 2025, 5:59 AM
Wisdom Emmanuel
Wisdom Emmanuel - avatar