The path of the Python precipitation--a preliminary understanding of higher order functions

Source: Internet
Author: User

One, the higher order function: Two kinds: One is the return value contains the function body, the other is a function body as a parameter passed to another function

1. The return value contains the function body

Example 1,

1 def Test (): 2     Print (' This is a test ') 3     return Test 4 5 f = test ()6 F ()
1 This is a test 2 This is a test

Example 2

1 definward ():2     Print('From inward')3 defoutward ():4     Print('From outward')5     returnInward6 7f =Outward ()8F ()
1  from Outward 2  from Inward

2. Pass a function body as one parameter to another function

Example 1

 1  def   Inward (name):  2  print  ( " %s is from inward   %name)  3  4  def   Outward (n):  5  print  ("   I'm from outside the earth   " )  6  7  Outward (Inward ( '   I   )) 
1  is  from Inward 2 I come from outside the Earth

The path of the Python precipitation--a preliminary understanding of higher order functions

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.