Python functions, recursion, built-in functions

Source: Internet
Author: User

Directory

1. Basic function syntax and features

2. Parameters and Local variables

3. Return value

Nested functions

4. Recursion

5. Anonymous functions

6. Introduction to Functional programming

7. Higher-order functions

8. Built-in functions

1. Basic function syntax and features

function is derived from mathematics, but the concept of "function" in programming is very different from the function in mathematics, the specific difference, we will say later, the function of programming in English also has a lot of different names. In basic it is called subroutine (sub-process or subroutine), in Pascal is called procedure (process) and function, in C only function, in Java is called method.

Definition: A function that encapsulates a set of statements by a name (function name), and to execute the function, simply call the name of its functions

Characteristics:

    1. Reduce duplicate code
    2. To make the program extensible
    3. Make programs easier to maintain
Syntax definitions
Def sayhi (): #函数名    print ("Hello, I ' m nobody!") Sayhi () #调用函数

can take parameters

#下面这段代码a, b = 5,8c = A**bprint (c)  #改成用函数写def calc (x, y):    res = x**y    return res #返回函数执行结果 c = Calc (b) # result assigned to c variable Print (c)

  

Python functions, recursion, built-in functions

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.