Home > Backend Development > Python Tutorial > Detailed explanation of functions in Python

Detailed explanation of functions in Python

巴扎黑
Release: 2017-08-02 11:47:04
Original
2058 people have browsed it

Among them, some important function attributes include the following:

1. __doc__ returns the documentation string of the specified function.

2. __name__ returns the function name.

3. __module__ returns the name of the module where the function is defined.

4. func_defaults returns a tuple containing default parameter values. Default parameters will be discussed later.

5. func_globals returns a dictionary reference containing function global variables.

6. func_dict returns a namespace that supports arbitrary function attributes.

7. func_closure returns a cell body tuple, where the cell body contains the binding of function free variables. Closure will be discussed later.

Functions can be passed as parameters to other functions. These functions that take other functions as arguments are often called higher-order functions, and they form a very important part of functional programming. A good example of a higher-order function is the map function, which takes a function and an iterator as arguments, applies the function to each item in the iterator, and returns a new list. We will demonstrate this in the following example, where the square function defined earlier and a numeric iterator are passed to the map function.

The above is the detailed content of Detailed explanation of functions in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template