Huanggo code to illustrate: Python syntax sugar

Source: Internet
Author: User

Here is an example to illustrate:

#coding: Utf-8

"""

The function of the Foo = decorator (foo) statement is to pass the Foo function as a parameter to the decorator

The return value is assigned to Foo, so Foo is no longer the original function.

To simplify the code, Python adds an adorner to this syntactic sugar

Makes

@decorator

def foo ():

Print ("Welcome to Huanggo Python training")

Print ("Consulting qq:1465376564")

Print ("Https://github.com/pythonpeixun/article/blob/master/index.md")

The same effect as Foo = decorator (foo)

"""

def decorator (func):

def inner ():

Print ("Begin func Call")

Func ()

Print ("After func call")

return inner

def foo ():

Print ("Welcome to Huanggo Python training")

Print ("Consulting qq:1465376564")

Print ("Https://github.com/pythonpeixun/article/blob/master/index.md")

@decorator

Def foo2 ():

Print ("Welcome to Huanggo Python training")

Print ("Consulting qq:1465376564")

Print ("Https://github.com/pythonpeixun/article/blob/master/index.md")

foo = decorator (foo)

Foo ()

Print ("***************************")

Foo2 ()

Huanggo Python Remote Video training course

Https://github.com/pythonpeixun/article/blob/master/index.md

Huanggo Python training preview video playback address

Https://github.com/pythonpeixun/article/blob/master/python_shiping.md

Huanggo python training _python Beginner's first step

http://www.tudou.com/programs/view/pZvrOt9RlmE/

How to poke a python-programmed layer of paper video

http://www.tudou.com/programs/view/ppJv6Kf08Ac/


Huanggo code to illustrate: Python syntax sugar

Related Article

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.