A detailed description of function nesting methods using Python

Source: Internet
Author: User
The Python language allows the function body to have a complete definition of another function when defining a function, which is what we typically call nested definitions.

Example 1:

Def outfun ():         #定义函数OutFun (),    m=3               #定义变量m =3;    Def infun ():      #在OutFun内定义函数InFun ()        n=4           #定义局部变量n =4        print m+n     #m相当于函数InFun () global variable     infun ()          Call Function Infun () in #OutFun () function

Example 2:

def infun (m):    n=4    print m+ndef outfun ()     m=4     infun (m)

Instance 2 first defines the function Infun (), and then again defines the Outfun () function, at which time Infun () and Outfun () are completely independent of the two functions, again Outfun () function calls Infun (), in fact, instance 1 and instance 2 have the same nesting effect, Just two different forms of expression.

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.