Python basic syntax-functions

Source: Internet
Author: User
Function

(a) Concept: A code snippet that implements a single function or related function, maximizing the reuse code of a function class

(b) Function definition:

def 函数名 (参数列表)    函数体    return [表达式]    #返回的“表达式”是选择性的;如果没有value返回,那么返回值是None

Example (1): Parameter has a return

def Sum(x, y):    sum = x + y    return sum#函数调用sum = Sum(1, 2)print(sum)输出结果:3

Example (2): There are multiple returns

def x_y_comp_tuple(x, y):    res1 = x + y    res2 = x * y    return res1, res2a, b = x_y_comp_tuple(2, 3)print("a = {}, b = {}".format(a, b))输出结果:a = 5, b = 6

Example (3): List as return value

 稍后填充

Python basic syntax-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.