Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 07

Python @decorator Syntax — Stack square, sqrt, cube, and Text Pipelines

Learn @ decorator syntax visually: phone-plus-apps analogy, bottom-up stack order, stacked math tuple, and text pipeline.

Intermediate40 min

![at decorator syntax stacked layers hero banner](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20640%20220%27%3E%20%3Cdefs%3E%20%3ClinearGradient%20id%3D%27igdstk7h%27%20x1%3D%270%27%20y1%3D%270%27%20x2%3D%271%27%20y2%3D%271%27%3E%20%3Cstop%20offset%3D%270%25%27%20stop-color%3D%27%237C3AED%27%2F%3E%20%3Cstop%20offset%3D%2755%25%27%20stop-color%3D%27%232563EB%27%2F%3E%20%3Cstop%20offset%3D%27100%25%27%20stop-color%3D%27%230F172A%27%2F%3E%20%3C%2FlinearGradient%3E%20%3C%2Fdefs%3E%20%3Crect%20width%3D%27640%27%20height%3D%27220%27%20rx%3D%2720%27%20fill%3D%27url%28%23igdstk7h%29%27%2F%3E%20%3Crect%20x%3D%2736%27%20y%3D%2736%27%20width%3D%27360%27%20height%3D%27148%27%20rx%3D%2714%27%20fill%3D%27%230F172A%27%20opacity%3D%270.45%27%2F%3E%20%3Ctext%20x%3D%2752%27%20y%3D%2768%27%20fill%3D%27%23C4B5FD%27%20font-size%3D%2712%27%20font-weight%3D%27bold%27%3ELESSON%2007%20%C2%B7%20%40%20SYNTAX%3C%2Ftext%3E%20%3Ctext%20x%3D%2752%27%20y%3D%2798%27%20fill%3D%27%23FFFFFF%27%20font-size%3D%2720%27%20font-weight%3D%27bold%27%3EUnderstand%20%40%20Decorators%20Visually%3C%2Ftext%3E%20%3Ctext%20x%3D%2752%27%20y%3D%27122%27%20fill%3D%27%23E2E8F0%27%20font-size%3D%2712%27%3ELayers%20wrap%20a%20function%20%E2%80%94%20bottom%20decorator%20runs%20first%3C%2Ftext%3E%20%3Ctext%20x%3D%2752%27%20y%3D%27148%27%20fill%3D%27%23A5B4FC%27%20font-size%3D%2711%27%3E%40stack%20%C2%B7%20tuple%20pipeline%20%C2%B7%20text%20filters%3C%2Ftext%3E%20%3Crect%20x%3D%27420%27%20y%3D%2748%27%20width%3D%27184%27%20height%3D%27124%27%20rx%3D%2712%27%20fill%3D%27%23FFFFFF%27%20opacity%3D%270.12%27%2F%3E%20%3Ctext%20x%3D%27440%27%20y%3D%2778%27%20fill%3D%27%23FDE68A%27%20font-size%3D%2710%27%20font-family%3D%27Courier%20New%27%3E%40square%3C%2Ftext%3E%20%3Ctext%20x%3D%27440%27%20y%3D%2798%27%20fill%3D%27%23BBF7D0%27%20font-size%3D%2710%27%20font-family%3D%27Courier%20New%27%3E%40squareroot%3C%2Ftext%3E%20%3Ctext%20x%3D%27440%27%20y%3D%27118%27%20fill%3D%27%23E0F2FE%27%20font-size%3D%2710%27%20font-family%3D%27Courier%20New%27%3E%40cube%3C%2Ftext%3E%20%3Ctext%20x%3D%27440%27%20y%3D%27138%27%20fill%3D%27%23FBCFE8%27%20font-size%3D%2710%27%20font-family%3D%27Courier%20New%27%3EgetLine%20pipeline%3C%2Ftext%3E%20%3Ctext%20x%3D%27440%27%20y%3D%27158%27%20fill%3D%27%23FECACA%27%20font-size%3D%2710%27%3Ebottom%20up%20order%3C%2Ftext%3E%20%3C%2Fsvg%3E

Understand @ Decorators Visually

Think of decorators as layers that wrap a function and add new abilities — without changing the original function.

A decorator is like adding apps to your phone

The phone stays the same. Each app adds a new capability. That is exactly what @square, @cube, and @squareroot do.

Real-life analogy: your phone

Imagine you buy a new phone. It can only make calls. Then you install apps. The phone never changes — only its abilities grow.

![smartphone illustration getval original phone only calling](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20160%20180%27%3E%20%3Crect%20width%3D%27160%27%20height%3D%27180%27%20rx%3D%2714%27%20fill%3D%27%23F8FAFC%27%2F%3E%20%3Crect%20x%3D%2748%27%20y%3D%2720%27%20width%3D%2764%27%20height%3D%27120%27%20rx%3D%2712%27%20fill%3D%27%23E5E7EB%27%20stroke%3D%27%239CA3AF%27%20stroke-width%3D%272%27%2F%3E%20%3Crect%20x%3D%2754%27%20y%3D%2732%27%20width%3D%2752%27%20height%3D%2788%27%20rx%3D%276%27%20fill%3D%27%23FFFFFF%27%2F%3E%20%3Ccircle%20cx%3D%2780%27%20cy%3D%27130%27%20r%3D%276%27%20fill%3D%27%23D1D5DB%27%2F%3E%20%3Crect%20x%3D%2768%27%20y%3D%2724%27%20width%3D%2724%27%20height%3D%274%27%20rx%3D%272%27%20fill%3D%27%239CA3AF%27%2F%3E%20%3Ctext%20x%3D%2780%27%20y%3D%2758%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23374151%27%3EPhone%3C%2Ftext%3E%20%3Ctext%20x%3D%2780%27%20y%3D%2772%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%236B7280%27%3Egetval%28%29%3C%2Ftext%3E%20%3Ctext%20x%3D%2780%27%20y%3D%2786%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%2364748B%27%3Ecalls%20only%3C%2Ftext%3E%20%3Ctext%20x%3D%2780%27%20y%3D%27158%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23374151%27%3EOriginal%3C%2Ftext%3E%20%3Ctext%20x%3D%2780%27%20y%3D%27170%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%2364748B%27%3EOnly%20calling%3C%2Ftext%3E%20%3C%2Fsvg%3E

![smartphone with decorator app icons square sqrt cube extra features](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20160%20180%27%3E%20%3Crect%20width%3D%27160%27%20height%3D%27180%27%20rx%3D%2714%27%20fill%3D%27%23F8FAFC%27%2F%3E%20%3Crect%20x%3D%2748%27%20y%3D%2720%27%20width%3D%2764%27%20height%3D%27120%27%20rx%3D%2712%27%20fill%3D%27%23DBEAFE%27%20stroke%3D%27%232563EB%27%20stroke-width%3D%272%27%2F%3E%20%3Crect%20x%3D%2754%27%20y%3D%2732%27%20width%3D%2752%27%20height%3D%2788%27%20rx%3D%276%27%20fill%3D%27%23EFF6FF%27%2F%3E%20%3Ccircle%20cx%3D%2780%27%20cy%3D%27130%27%20r%3D%276%27%20fill%3D%27%2393C5FD%27%2F%3E%20%3Crect%20x%3D%2758%27%20y%3D%2740%27%20width%3D%2718%27%20height%3D%2718%27%20rx%3D%274%27%20fill%3D%27%23DDD6FE%27%2F%3E%20%3Ctext%20x%3D%2767%27%20y%3D%2752%27%20font-size%3D%276%27%20text-anchor%3D%27middle%27%20fill%3D%27%235B21B6%27%3Esq%3C%2Ftext%3E%20%3Crect%20x%3D%2782%27%20y%3D%2740%27%20width%3D%2718%27%20height%3D%2718%27%20rx%3D%274%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%2791%27%20y%3D%2752%27%20font-size%3D%276%27%20text-anchor%3D%27middle%27%20fill%3D%27%23047857%27%3Ert%3C%2Ftext%3E%20%3Crect%20x%3D%2758%27%20y%3D%2764%27%20width%3D%2718%27%20height%3D%2718%27%20rx%3D%274%27%20fill%3D%27%23FDE68A%27%2F%3E%20%3Ctext%20x%3D%2767%27%20y%3D%2776%27%20font-size%3D%276%27%20text-anchor%3D%27middle%27%20fill%3D%27%2392400E%27%3Ecb%3C%2Ftext%3E%20%3Crect%20x%3D%2782%27%20y%3D%2764%27%20width%3D%2718%27%20height%3D%2718%27%20rx%3D%274%27%20fill%3D%27%23FBCFE8%27%2F%3E%20%3Ctext%20x%3D%2791%27%20y%3D%2776%27%20font-size%3D%276%27%20text-anchor%3D%27middle%27%20fill%3D%27%23BE185D%27%3E%2B%3C%2Ftext%3E%20%3Ctext%20x%3D%2780%27%20y%3D%27158%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%231D4ED8%27%3EPhone%20%2B%20Apps%3C%2Ftext%3E%20%3Ctext%20x%3D%2780%27%20y%3D%27170%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%232563EB%27%3EExtra%20features%3C%2Ftext%3E%20%3C%2Fsvg%3E

![getval phone with square sqrt cube decorator apps to enhanced function](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%2090%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%2790%27%20rx%3D%2712%27%20fill%3D%27%23EEF2FF%27%2F%3E%20%3Crect%20x%3D%2712%27%20y%3D%2725%27%20width%3D%2764%27%20height%3D%2740%27%20rx%3D%278%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%2744%27%20y%3D%2740%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%231D4ED8%27%3Egetval%3C%2Ftext%3E%20%3Ctext%20x%3D%2744%27%20y%3D%2754%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%231E40AF%27%3Ephone%3C%2Ftext%3E%20%3Cpath%20d%3D%27M76%2045%20H96%27%20stroke%3D%27%2364748B%27%20stroke-dasharray%3D%273%203%27%2F%3E%20%3Crect%20x%3D%27100%27%20y%3D%2714%27%20width%3D%2748%27%20height%3D%2718%27%20rx%3D%276%27%20fill%3D%27%23DDD6FE%27%2F%3E%20%3Ctext%20x%3D%27124%27%20y%3D%2726%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%235B21B6%27%3E%40square%3C%2Ftext%3E%20%3Crect%20x%3D%27100%27%20y%3D%2736%27%20width%3D%2748%27%20height%3D%2718%27%20rx%3D%276%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%27124%27%20y%3D%2748%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%23047857%27%3E%40sqrt%3C%2Ftext%3E%20%3Crect%20x%3D%27100%27%20y%3D%2758%27%20width%3D%2748%27%20height%3D%2718%27%20rx%3D%276%27%20fill%3D%27%23FDE68A%27%2F%3E%20%3Ctext%20x%3D%27124%27%20y%3D%2770%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%2392400E%27%3E%40cube%3C%2Ftext%3E%20%3Cpath%20d%3D%27M148%2045%20H168%27%20stroke%3D%27%2364748B%27%20stroke-dasharray%3D%273%203%27%2F%3E%20%3Crect%20x%3D%27172%27%20y%3D%2725%27%20width%3D%27136%27%20height%3D%2740%27%20rx%3D%278%27%20fill%3D%27%232563EB%27%2F%3E%20%3Ctext%20x%3D%27240%27%20y%3D%2740%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23FFFFFF%27%3EEnhanced%20fn%3C%2Ftext%3E%20%3Ctext%20x%3D%27240%27%20y%3D%2754%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%23DBEAFE%27%3Ewrapped%3C%2Ftext%3E%20%3C%2Fsvg%3E

Python translation:

Real life Python
Phone getval()
Apps Decorators
Enhanced phone Wrapped function

What you will learn

  • @square above def getval equals getval = square(getval)
  • @square unpacks num, result
  • Stacked @cube @squareroot @square — closest decorator runs first
  • Text pipeline: upper, lower, reverse words
  • Playground literals: 5.0 and "Python Filter Map" — no input()

What @square actually means

These two are 100% identical:

![without at getval equals square getval same as at square shorthand](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%2090%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%2790%27%20rx%3D%2712%27%20fill%3D%27%23F8FAFC%27%2F%3E%20%3Crect%20x%3D%2716%27%20y%3D%2716%27%20width%3D%27132%27%20height%3D%2758%27%20rx%3D%278%27%20fill%3D%27%23FEE2E2%27%20stroke%3D%27%23EF4444%27%2F%3E%20%3Ctext%20x%3D%2782%27%20y%3D%2734%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23991B1B%27%3EWithout%20%40%3C%2Ftext%3E%20%3Ctext%20x%3D%2782%27%20y%3D%2748%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%237F1D1D%27%3Egetval%20%3D%20square%28getval%29%3C%2Ftext%3E%20%3Crect%20x%3D%27172%27%20y%3D%2716%27%20width%3D%27132%27%20height%3D%2758%27%20rx%3D%278%27%20fill%3D%27%23D1FAE5%27%20stroke%3D%27%23059669%27%2F%3E%20%3Ctext%20x%3D%27238%27%20y%3D%2734%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23047857%27%3EWith%20%40%3C%2Ftext%3E%20%3Ctext%20x%3D%27238%27%20y%3D%2748%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%23065F46%27%3E%40square%20above%20def%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2782%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%2364748B%27%3E100%25%20identical%20behavior%3C%2Ftext%3E%20%3C%2Fsvg%3E

Without @:

python
def getval():
    return 5.0

getval = square(getval)

With @:

python
@square
def getval():
    return 5.0

Easy memory rule:

@square = "After creating this function, wrap it with square()."

@square

python
def square(m):
    def calculate():
        n = m()
        res = n ** 2
        return n, res
    return calculate

@square
def getval():
    return 5.0

num, result = getval()
print("Square({})={}".format(num, result))

Calling getval() actually runs calculate.

Execution order — the biggest interview question

Many students think decorators run top to bottom. Wrong. They execute from the bottom upward — the decorator closest to def runs first.

![stacked cube squareroot square bottom decorator executes first](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%20170%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%27170%27%20rx%3D%2714%27%20fill%3D%27%23F8FAFC%27%2F%3E%20%3Crect%20x%3D%2770%27%20y%3D%2712%27%20width%3D%27180%27%20height%3D%2724%27%20rx%3D%276%27%20fill%3D%27%23FDE68A%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2728%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%2392400E%27%3E%40cube%3C%2Ftext%3E%20%3Crect%20x%3D%2770%27%20y%3D%2746%27%20width%3D%27180%27%20height%3D%2724%27%20rx%3D%276%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2762%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23047857%27%3E%40squareroot%3C%2Ftext%3E%20%3Crect%20x%3D%2770%27%20y%3D%2780%27%20width%3D%27180%27%20height%3D%2724%27%20rx%3D%276%27%20fill%3D%27%23DDD6FE%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2796%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%235B21B6%27%3E%40square%3C%2Ftext%3E%20%3Crect%20x%3D%2770%27%20y%3D%27114%27%20width%3D%27180%27%20height%3D%2724%27%20rx%3D%276%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27130%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%231D4ED8%27%3Edef%20getval%28%29%3C%2Ftext%3E%20%3Cpath%20d%3D%27M30%20126%20V88%27%20stroke%3D%27%232563EB%27%20stroke-width%3D%272%27%20stroke-dasharray%3D%274%204%27%2F%3E%20%3Ctext%20x%3D%2738%27%20y%3D%27108%27%20font-size%3D%277%27%20fill%3D%27%232563EB%27%3E1st%3C%2Ftext%3E%20%3Cpath%20d%3D%27M290%2092%20V54%27%20stroke%3D%27%23047857%27%20stroke-width%3D%272%27%20stroke-dasharray%3D%274%204%27%2F%3E%20%3Ctext%20x%3D%27250%27%20y%3D%2772%27%20font-size%3D%277%27%20fill%3D%27%23047857%27%3E2nd%3C%2Ftext%3E%20%3Cpath%20d%3D%27M160%2048%20V22%27%20stroke%3D%27%23D97706%27%20stroke-width%3D%272%27%20stroke-dasharray%3D%274%204%27%2F%3E%20%3Ctext%20x%3D%27170%27%20y%3D%2736%27%20font-size%3D%277%27%20fill%3D%27%23D97706%27%3E3rd%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27154%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23374151%27%3EBottom%20decorator%20executes%20first%3C%2Ftext%3E%20%3C%2Fsvg%3E

python
@cube
@squareroot
@square
def getval():
    return 5.0

Execution order:

  1. @square (closest to def)
  2. @squareroot
  3. @cube (outermost)

Interactive math decorator stack

Change the number in the playground and watch every decorator add a new value. With 5.0:

![interactive math decorator stack getval square squareroot cube tuple](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%20220%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%27220%27%20rx%3D%2714%27%20fill%3D%27%23F8FAFC%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2720%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%2364748B%27%3EOriginal%20number%20%28getval%29%3A%205.0%3C%2Ftext%3E%20%3Crect%20x%3D%2720%27%20y%3D%2730%27%20width%3D%27280%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%2732%27%20y%3D%2744%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%231D4ED8%27%3EOriginal%20function%3C%2Ftext%3E%20%3Ctext%20x%3D%27288%27%20y%3D%2744%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%231D4ED8%27%3Egetval%28%29%20%E2%86%92%205%3C%2Ftext%3E%20%3Crect%20x%3D%2720%27%20y%3D%2772%27%20width%3D%27280%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23EDE9FE%27%2F%3E%20%3Ctext%20x%3D%2732%27%20y%3D%2786%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%235B21B6%27%3E%40square%3C%2Ftext%3E%20%3Ctext%20x%3D%27288%27%20y%3D%2786%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%235B21B6%27%3Eadds%3A%2025%3C%2Ftext%3E%20%3Crect%20x%3D%2720%27%20y%3D%27114%27%20width%3D%27280%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%2732%27%20y%3D%27128%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%23047857%27%3E%40squareroot%3C%2Ftext%3E%20%3Ctext%20x%3D%27288%27%20y%3D%27128%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%23047857%27%3Eadds%3A%202.236%3C%2Ftext%3E%20%3Crect%20x%3D%2720%27%20y%3D%27156%27%20width%3D%27280%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23FDE68A%27%2F%3E%20%3Ctext%20x%3D%2732%27%20y%3D%27170%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%2392400E%27%3E%40cube%3C%2Ftext%3E%20%3Ctext%20x%3D%27288%27%20y%3D%27170%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%2392400E%27%3Eadds%3A%20125%3C%2Ftext%3E%20%3Crect%20x%3D%2740%27%20y%3D%27198%27%20width%3D%27240%27%20height%3D%2718%27%20rx%3D%276%27%20fill%3D%27%232563EB%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27210%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23FFFFFF%27%3E%285%2C%2025%2C%202.236%2C%20125%29%3C%2Ftext%3E%20%3C%2Fsvg%3E

Stacked math decorators

Change the number in the playground and watch every decorator add a new value. With 5.0:

![math decorator stack square squareroot cube tuple 5 25 2.236 125](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%20130%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%27130%27%20rx%3D%2712%27%20fill%3D%27%23F8FAFC%27%2F%3E%20%3Ctext%20x%3D%2720%27%20y%3D%2722%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%2364748B%27%3Egetval%28%29%20returns%205.0%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%2732%27%20width%3D%27288%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23EDE9FE%27%2F%3E%20%3Ctext%20x%3D%2728%27%20y%3D%2746%27%20font-size%3D%278%27%20fill%3D%27%235B21B6%27%3E%40square%3C%2Ftext%3E%20%3Ctext%20x%3D%27280%27%20y%3D%2746%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%235B21B6%27%3E5%2C%2025%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%2758%27%20width%3D%27288%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%2728%27%20y%3D%2772%27%20font-size%3D%278%27%20fill%3D%27%23047857%27%3E%40squareroot%3C%2Ftext%3E%20%3Ctext%20x%3D%27280%27%20y%3D%2772%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%23047857%27%3E5%2C%2025%2C%202.236%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%2784%27%20width%3D%27288%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23FDE68A%27%2F%3E%20%3Ctext%20x%3D%2728%27%20y%3D%2798%27%20font-size%3D%278%27%20fill%3D%27%2392400E%27%3E%40cube%3C%2Ftext%3E%20%3Ctext%20x%3D%27280%27%20y%3D%2798%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%2392400E%27%3E5%2C%2025%2C%202.236%2C%20125%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27120%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%2364748B%27%3EFinal%20tuple%20from%20stack%3C%2Ftext%3E%20%3C%2Fsvg%3E

python
n, sqv, sqrtv, cb = getval()
# (5.0, 25.0, ~2.236, 125.0)

Application order (bottom first):

  1. square — (n, n**2)
  2. squareroot — adds n ** 0.5
  3. cube — adds n ** 3
python
n, sqv, sqrtv, cb = getval()
print("Square({})={}".format(n, sqv))
print("SquareRoot({})={}".format(n, sqrtv))
print("Cube({})={}".format(n, cb))

For 5.0: square 25.0, square root ≈ 2.236, cube 125.0.

Data flows through each layer

Think of decorators like a factory conveyor belt. Every decorator keeps the previous result and appends something new.

![conveyor belt data flow getval square squareroot cube layers](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%20210%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%27210%27%20rx%3D%2714%27%20fill%3D%27%23EFF6FF%27%2F%3E%20%3Crect%20x%3D%2728%27%20y%3D%2712%27%20width%3D%27264%27%20height%3D%2732%27%20rx%3D%278%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%2740%27%20y%3D%2724%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%231D4ED8%27%3Egetval%28%29%3C%2Ftext%3E%20%3Ctext%20x%3D%27280%27%20y%3D%2724%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%231D4ED8%27%3E5%3C%2Ftext%3E%20%3Crect%20x%3D%2728%27%20y%3D%2758%27%20width%3D%27264%27%20height%3D%2732%27%20rx%3D%278%27%20fill%3D%27%23EDE9FE%27%2F%3E%20%3Ctext%20x%3D%2740%27%20y%3D%2770%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%235B21B6%27%3E%40square%3C%2Ftext%3E%20%3Ctext%20x%3D%27280%27%20y%3D%2770%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%235B21B6%27%3E5%2C%2025%3C%2Ftext%3E%20%3Crect%20x%3D%2728%27%20y%3D%27104%27%20width%3D%27264%27%20height%3D%2732%27%20rx%3D%278%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%2740%27%20y%3D%27116%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%23047857%27%3E%40squareroot%3C%2Ftext%3E%20%3Ctext%20x%3D%27280%27%20y%3D%27116%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%23047857%27%3E5%2C%2025%2C%202.236%3C%2Ftext%3E%20%3Crect%20x%3D%2728%27%20y%3D%27150%27%20width%3D%27264%27%20height%3D%2732%27%20rx%3D%278%27%20fill%3D%27%23FDE68A%27%2F%3E%20%3Ctext%20x%3D%2740%27%20y%3D%27162%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%2392400E%27%3E%40cube%3C%2Ftext%3E%20%3Ctext%20x%3D%27280%27%20y%3D%27162%27%20font-size%3D%278%27%20text-anchor%3D%27end%27%20fill%3D%27%2392400E%27%3E5%2C%2025%2C%202.236%2C%20125%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27198%27%20font-size%3D%277%27%20text-anchor%3D%27middle%27%20fill%3D%27%2364748B%27%3EEach%20layer%20keeps%20previous%20values%20and%20appends%20new%20ones%3C%2Ftext%3E%20%3C%2Fsvg%3E

Text pipeline = Instagram caption editor

Imagine you are editing a caption before posting — like an Instagram caption editor. The original caption goes through three editors:

![uppercase caption editor Python Filter Map to PYTHON FILTER MAP](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20200%20120%27%3E%20%3Crect%20width%3D%27200%27%20height%3D%27120%27%20rx%3D%2712%27%20fill%3D%27%23EFF6FF%27%20stroke%3D%27%232563EB%27%20stroke-width%3D%271.5%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2722%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%231D4ED8%27%3E1%20%C2%B7%20Uppercase%20editor%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%2732%27%20width%3D%27168%27%20height%3D%2728%27%20rx%3D%276%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2750%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%231E40AF%27%20font-family%3D%27Courier%20New%27%3EA%20B%20C%20D%20E%20F%20G%20H%20I%3C%2Ftext%3E%20%3Cpath%20d%3D%27M100%2064%20V74%27%20stroke%3D%27%2364748B%27%20stroke-dasharray%3D%273%203%27%20marker-end%3D%27url%28%23arr%29%27%2F%3E%20%3Crect%20x%3D%2716%27%20y%3D%2778%27%20width%3D%27168%27%20height%3D%2728%27%20rx%3D%276%27%20fill%3D%27%232563EB%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2796%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23FFFFFF%27%20font-family%3D%27Courier%20New%27%3EPYTHON%20FILTER%20MAP%3C%2Ftext%3E%20%3C%2Fsvg%3E

![lowercase caption editor to python filter map](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20200%20120%27%3E%20%3Crect%20width%3D%27200%27%20height%3D%27120%27%20rx%3D%2712%27%20fill%3D%27%23ECFDF5%27%20stroke%3D%27%23059669%27%20stroke-width%3D%271.5%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2722%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23047857%27%3E2%20%C2%B7%20Lowercase%20editor%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%2732%27%20width%3D%27168%27%20height%3D%2728%27%20rx%3D%276%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2750%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23065F46%27%20font-family%3D%27Courier%20New%27%3Ea%20b%20c%20d%20e%20f%20g%20h%20i%3C%2Ftext%3E%20%3Cpath%20d%3D%27M100%2064%20V74%27%20stroke%3D%27%2364748B%27%20stroke-dasharray%3D%273%203%27%2F%3E%20%3Crect%20x%3D%2716%27%20y%3D%2778%27%20width%3D%27168%27%20height%3D%2728%27%20rx%3D%276%27%20fill%3D%27%23059669%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2796%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23FFFFFF%27%20font-family%3D%27Courier%20New%27%3Epython%20filter%20map%3C%2Ftext%3E%20%3C%2Fsvg%3E

![reverse word editor nohtyP retliF paM](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20200%20120%27%3E%20%3Crect%20width%3D%27200%27%20height%3D%27120%27%20rx%3D%2712%27%20fill%3D%27%23FAF5FF%27%20stroke%3D%27%237C3AED%27%20stroke-width%3D%271.5%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2722%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%236D28D9%27%3E3%20%C2%B7%20Reverse-word%20editor%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%2732%27%20width%3D%27168%27%20height%3D%2728%27%20rx%3D%276%27%20fill%3D%27%23EDE9FE%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2750%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%235B21B6%27%20font-family%3D%27Courier%20New%27%3EPython%20%E2%86%92%20nohtyP%3C%2Ftext%3E%20%3Cpath%20d%3D%27M100%2064%20V74%27%20stroke%3D%27%2364748B%27%20stroke-dasharray%3D%273%203%27%2F%3E%20%3Crect%20x%3D%2716%27%20y%3D%2778%27%20width%3D%27168%27%20height%3D%2728%27%20rx%3D%276%27%20fill%3D%27%237C3AED%27%2F%3E%20%3Ctext%20x%3D%27100%27%20y%3D%2796%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23FFFFFF%27%20font-family%3D%27Courier%20New%27%3EnohtyP%20retliF%20paM%3C%2Ftext%3E%20%3C%2Fsvg%3E

  1. Uppercase editor — @convertupper
  2. Lowercase editor — @convertlower
  3. Reverse-word editor — @reversewords

Interactive text decorator pipeline

Type any sentence in the playground and see each decorator transform it step by step:

![interactive text decorator pipeline upper lower reverse words](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%20160%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%27160%27%20rx%3D%2714%27%20fill%3D%27%23FAF5FF%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2718%27%20font-size%3D%279%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%236D28D9%27%3EPython%20Filter%20Map%20%E2%86%92%20three%20transforms%3C%2Ftext%3E%20%3Crect%20x%3D%2712%27%20y%3D%2728%27%20width%3D%27296%27%20height%3D%2726%27%20rx%3D%276%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%2724%27%20y%3D%2744%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%231D4ED8%27%3EOriginal%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2744%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3EPython%20Filter%20Map%3C%2Ftext%3E%20%3Crect%20x%3D%2712%27%20y%3D%2760%27%20width%3D%27296%27%20height%3D%2726%27%20rx%3D%276%27%20fill%3D%27%23EDE9FE%27%2F%3E%20%3Ctext%20x%3D%2724%27%20y%3D%2776%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%235B21B6%27%3E%40convertupper%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2776%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3EPYTHON%20FILTER%20MAP%3C%2Ftext%3E%20%3Crect%20x%3D%2712%27%20y%3D%2792%27%20width%3D%27296%27%20height%3D%2726%27%20rx%3D%276%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%2724%27%20y%3D%27108%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%23047857%27%3E%40convertlower%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27108%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3Epython%20filter%20map%3C%2Ftext%3E%20%3Crect%20x%3D%2712%27%20y%3D%27124%27%20width%3D%27296%27%20height%3D%2726%27%20rx%3D%276%27%20fill%3D%27%23FCE7F3%27%2F%3E%20%3Ctext%20x%3D%2724%27%20y%3D%27140%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%23BE185D%27%3E%40reversewords%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27140%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3EnohtyP%20retliF%20paM%3C%2Ftext%3E%20%3C%2Fsvg%3E

![text pipeline Python Filter Map upper lower reverse words text pipeline](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%20200%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%27200%27%20rx%3D%2714%27%20fill%3D%27%23FAF5FF%27%2F%3E%20%3Crect%20x%3D%2716%27%20y%3D%2710%27%20width%3D%27288%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%2726%27%20y%3D%2722%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%231D4ED8%27%3EOriginal%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2733%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3EPython%20Filter%20Map%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%2756%27%20width%3D%27288%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23EDE9FE%27%2F%3E%20%3Ctext%20x%3D%2726%27%20y%3D%2768%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%235B21B6%27%3E%40convertupper%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2779%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3EPYTHON%20FILTER%20MAP%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%27102%27%20width%3D%27288%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%2726%27%20y%3D%27114%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%23047857%27%3E%40convertlower%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27125%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3Epython%20filter%20map%3C%2Ftext%3E%20%3Crect%20x%3D%2716%27%20y%3D%27148%27%20width%3D%27288%27%20height%3D%2734%27%20rx%3D%278%27%20fill%3D%27%23FCE7F3%27%2F%3E%20%3Ctext%20x%3D%2726%27%20y%3D%27160%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20fill%3D%27%23BE185D%27%3E%40reversewords%3C%2Ftext%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27171%27%20font-size%3D%278%27%20text-anchor%3D%27middle%27%20fill%3D%27%23111827%27%3EnohtyP%20retliF%20paM%3C%2Ftext%3E%20%3C%2Fsvg%3E

Stacked text transforms:

python
@reversewords
@convertlower
@convertupper
def getLine():
    return "Python Filter Map"

Bottom first: original line, then upper, then lower, then each word reversed. The example below also prints rwd.upper() and rwd.lower() of the reversed string.

python
NL, UL, LL, rwd = getLine()
print("Given:", NL)
print("Upper:", UL)
print("Lower:", LL)
print("Reversed upper:", rwd.upper())
print("Reversed lower:", rwd.lower())

Run the full script in the playground below.

Three common mistakes

  1. Reading top to bottom — decorators execute bottom first (closest @ to def).
  2. Forgetting to call the wrapped function — inside the decorator, use m(), not just m.
  3. Thinking @ is magic syntax — it is simply shorthand for function = decorator(function).

Interview cheat sheet

Question Answer
What does @f mean? name = f(name)
Stack order? Bottom decorator first
Inner function must? Call the wrapped callable (m(), m())
Stacked math unpack? n, square, sqrt, cube

30-second memory map

![getval at square at squareroot at cube result tuple recap](data:image/svg+xml;charset=utf-8,%3Csvg%20font-family%3D%27ui-sans-serif%2C-apple-system%2Csystem-ui%2CArial%27%20width%3D%27100%25%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%20320%20190%27%3E%20%3Crect%20width%3D%27320%27%20height%3D%27190%27%20rx%3D%2714%27%20fill%3D%27%23F8FAFC%27%2F%3E%20%3Crect%20x%3D%2760%27%20y%3D%2710%27%20width%3D%27200%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23DBEAFE%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2725%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%231D4ED8%27%3Egetval%28%29%3C%2Ftext%3E%20%3Crect%20x%3D%2760%27%20y%3D%2744%27%20width%3D%27200%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23EDE9FE%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2759%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%235B21B6%27%3E%40square%3C%2Ftext%3E%20%3Crect%20x%3D%2760%27%20y%3D%2778%27%20width%3D%27200%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23D1FAE5%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%2793%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23047857%27%3E%40squareroot%3C%2Ftext%3E%20%3Crect%20x%3D%2760%27%20y%3D%27112%27%20width%3D%27200%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23FDE68A%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27127%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%2392400E%27%3E%40cube%3C%2Ftext%3E%20%3Crect%20x%3D%2760%27%20y%3D%27146%27%20width%3D%27200%27%20height%3D%2722%27%20rx%3D%276%27%20fill%3D%27%23F3F4F6%27%2F%3E%20%3Ctext%20x%3D%27160%27%20y%3D%27161%27%20font-size%3D%278%27%20font-weight%3D%27bold%27%20text-anchor%3D%27middle%27%20fill%3D%27%23374151%27%3EResult%20tuple%3C%2Ftext%3E%20%3C%2Fsvg%3E

Remember this sentence:

@decorator wraps a function, stacked decorators execute from the bottom upward, and each layer adds new behavior without changing the original function.

Practice in the playground

  1. Change 5.0 to 4.0 and check cube 64.
  2. Change the sample line and confirm word reversal.
  3. Remove @cube and adjust the unpack (three values).

You finished Iterators, Generators, and Decorators. Revisit Lambda and special functions for lazy filter/map, or Functions for def and scope.

Loading playground…

Check your understanding

Decorator stacking quiz

@square above def getval is equivalent to:

1 / 10