Python built-in functions, anonymous functions, recursive

Source: Internet
Author: User

First, built-in functions

Built-in functions in detail: http://www.runoob.com/python/python-built-in-functions.html

Second, anonymous function

An anonymous function is one that does not require an explicit function to be specified

# this piece of code def Calc (n):3     return n**nprint(calc)5  #  Switch to anonymous function lambda n:n**nprint(Calc (10))

Characteristics:

1, Lambda is just an expression, function body is much simpler than def

2. The body of a lambda is an expression, not a block of code. Only a finite amount of logic can be encapsulated in a lambda expression.

3, call the small function without using the stack memory to increase operational efficiency.

Third, recursion

1, recursive call: Inside the function, you can call other functions. If you call itself directly or indirectly during a call to a function

#The final age of recursion.#Age (1) =age (2) +2#Age (2) =age (3) +2#Age (3) =age (4) +2#Age (4) =age (5) +2#Age (5) =18####Age (N) =age (n+1) +2 #n <5#Age (n) =18 #n =5#def Age (n):#if n = = 5:#return#return Age (n+1) +2###Print (age (1))

2. Characteristics of recursion

(1) must have a definite end condition

(2) Each time you enter a deeper level of recursion, the problem size should be reduced compared to the last recursion

(3) Recursive efficiency is not high

Python built-in functions, anonymous functions, recursive

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.