Python function basics

Source: Internet
Author: User

PYTHON4 functions: Global functions, local functions, lambda functions, methods

Many built-in functions

Syntax: def functionname (parameters):

Suite

Return is used to return the result object, which is optional: Returns multiple values separated by commas and grouped into tuples

Local variables, global variables, built-in variables

Global variable: Defining a Globals variable

Python's closures

Parameter passing form:

Position parameters: from left to right

Keyword parameters: matching by keyword name

Mix the above two ways: all positional parameters, all the keyword parameters

Use default parameters when defining functions: Parameters with default values

When mixing parameters with default and no default values, no default values are placed in front

Variable parameters: Parameters that start with * when defining a function, collect positional parameters, output tuple ()

When you define a function with a * * start, the phone keyword parameter, output dictionary {}

Variable parameter unpacking: When calling a function, use the * parameter, which can be used to scatter the parameter collection to pass any number of arguments based on the position or keyword

anonymous function lambda is an expression rather than a statement

Lambda Args:expression (args: A comma-separated variable)

Python function basics

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.