Python Function name Application

Source: Internet
Author: User

Application of Function name

application categories for function names:

A function is a special variable (which can be used as a variable)
* Memory address of function name corresponding function
* Function names can be used as elements of container class data
* Function name can be used as parameter of function
* Function name can be used as return value of function
* Function names can be arbitrarily assigned.
There is a name for such a function: the first class of functions

1. Print function name, display function memory address

Example:
# def func1 ():
# Print (666)
# Print (FUNC1)
Results:
# <function func1 at 0x000000000258f9d8>

2 function names can be used as elements of container class data

   Example:
Def func1 ():
Print (111)


Def FUNC2 ():
Print (222)

Def func3 ():
Print (333)

L1 = [Func1, Func2, func3]
For I in L1:
I () # # # #函数名加括号即执行函数

3 function names can be used as arguments to functions

Example:
Def func1 ():
Print (111)


def func2 (x):
Print (x)
X ()
Print (222)

Func2 (FUNC1)

4 function names can be used as return values for functions

   Example:
Def func1 ():
Return 111


def func2 (x): # x = func1
Print (222)
return x

ret = Func2 (func1) # func1
Print (ret ())
Print (ret)
Results:
222
111
<function func1 at 0x0215d810>

Description
#向这样的函数名 have a term: first Class object
Python contains functions such as everything is an object, the function as the first class object, support assignment to the variable, as a parameter to other functions, as the return value of other functions, supporting the nesting of functions, the implementation of the __call__ method of the class instance object can also be called as a function.

Python Function name Application

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.