Python function programming

Source: Internet
Author: User

1. function is a programming method of logical structure and process

The function definition in Python uses the keyword def to define

def test (x):

"The function Definitions"

X+=1

return x

def: A keyword that defines a function

Test: Function Name

(): parameter can be defined within

X+=1: code block or program processing logic

Return: Define the return value

2, the function of the characteristics:

1. Reusability of code

2. Maintain consistency

3. Scalability

3. Functions and Procedures:

Procedure definition: A procedure is simply a function with no return value

The Python parser implicitly returns none when a function or procedure does not use return display to define the return value, so in Python

Even a process can be counted as a function.

4. Parameter group:

def test (*args):

*args: Represents a parameter group

When calling in a function, passing arguments can be 1 or more

Test (1,2,3,4,5,6)

Test (*[1,2,3,4,5])

This way: *args: Accept n Positional parameters, convert narimoto Group form

def test (**kvargs):

Test (name= "Zhangsan", age= "20")

This way: **kwargs: Accept n keyword arguments and convert them into dictionaries in a way that

Python function programming

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.