Closures and the @ symbol — what AI is doing when it stacks decorators — step 9 of 9
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Final drill. Build a decorator factory called prefixed that takes
a string and returns a decorator. The decorator wraps a function so
its return value gets the prefix prepended.
Use it like this:
@prefixed("[INFO] ")
def msg():
return "started"
print(msg()) # [INFO] started
Expected output:
[INFO] started
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Final drill. Build a decorator factory called prefixed that takes
a string and returns a decorator. The decorator wraps a function so
its return value gets the prefix prepended.
Use it like this:
@prefixed("[INFO] ")
def msg():
return "started"
print(msg()) # [INFO] started
Expected output:
[INFO] started
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.