Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 35,157 Points

"@" sign in Python decorators.

I am afraid to ask this. Might be silly. I've never seen @ signs in Python before. I am familiar with them from Java. Is there any relationship between the use of @ in Java annotations and its use in Python for decorators?

2 Answers

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hi Nancy Melucci

Actually that is not a silly question.

I think the best simple explanation I found of this was on this Stack Overflow Link

Python decorators are just syntactic sugar for passing a function to another function and replacing the first function with the result

Java annotations by themselves just store metadata, you must have something that inspects them to add behaviour.

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 35,157 Points

So there is no relationship between function and symbol...just a different use of the same code. Thanks.