Python @ Decorator Simple to understand

Source: Internet
Author: User

Personal learning python for a long time, but has always been here to pick a point where to learn, a little overwhelmed. Recently I want to see how the adorner used, and then studied the next.

Simple point of:

#!/usr/bin/python

def say (key): # Create a small function

print ' Your first love! '

Return key

@say

Def hold ():

print ' This is sercod world! '


Hold ()



A brief talk is @say

The Def hold () is a say wrap, the order of execution is say ("#参数就是 #hold function Overall #"), the simple is to put a function of the outer layer of a say function. But the final execution is hold, so the coat function say must point to hold, so the return value returns key----Here the key is the hold itself.



It's a bit of a mouthful, but it's good to understand. If you don't understand, there's no way.

This article is from the "Pang" blog, make sure to keep this source http://pangfei.blog.51cto.com/8832397/1731401

Python @ Decorator Simple to understand

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.