Basic Python Tutorial (second edition) Learning Note function (Chapter 6th)

Source: Internet
Author: User

Basic Python Tutorial (second edition) Learning Note function (Chapter 6th)

To create a function:
def function_name (params):
Block
Return values

Record function:
def function_name (params):
' NOTE ' #注释
Block
Return values

function_name.__doc__
Help (Function_name)

Return # no value returned

Position parameters and keyword parameters:
Keyword parameter to provide the name of the parameter:
def function_name (Name1=value1, name2=value2): #给参数提供了默认值
Block
Return values

Let the user provide any number of parameters:
def function_name (*params):
Block
Return values

def print_params (*params): #定义函数
Print params

Print_params (#调用函数)


Handle the collection of keyword parameters:
def function_name (**params):
Block
Return values

def print_params (**params): #定义函数
Print params

Print_params (x=1,y=2,z=3) #调用函数

def add (x, y): Return x+y
Params= (ON)
Add (*params)

Globals () [' Param_name ']
Locals () [' Param_name ']
Global X

Map () passes all the elements in a sequence to a function
Map (str, range (10))
Filter (func, seq)
Lambda expression
Filter (lambda x:x.isalnum (), seq)
Reduce () uses the first two elements of a sequence in conjunction with a given function, and continues to use their return value and the 3rd element until the entire sequence is processed.

Basic Python Tutorial (second edition) Learning Note function (Chapter 6th)

Related Article

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.