Python function Basics

Source: Internet
Author: User

In the last lesson, I shared some knowledge about Python statements. Today I will share with you the knowledge about Python functions.

We all know that using functions to replace the continuous copying process in the programming process can greatly reduceCodeWork to maximize code reuse and
Minimize code redundancy. Through functional programming, we can break down complex systems and solve problems better.

The following describes the basic knowledge of Python functions.

1 Python functions operate functions through def. Def is used to create an object and assign values to a variable.
When Python runs the def statement, it generates a function object and copies it to a function name. The function name is the reference of the function,
It is equivalent to storing the address of the function object in the function name.

2. The function returns the value through return or the yield statement.

3 python is passed through a value assignment, that is, object reference. If you pass variable values as immutable objects, they cannot be changed in the function.
The variable value of the caller, such as a string or number. If the passed variable is a mutable object, such as a list, it can be changed in the function.
The variable value of the caller. You can implement it. For more information about function parameters, see Python function parameters and key Python function parameters.

4. Parameters and return values do not need to be declared. to define a function from the very beginning, you do not need to declare the passed parameter type and return value like other languages.
. Python functions can pass arbitrary parameters to functions, and functions can return any type of objects, making programming easier.
For more information about parameters, see the special situations of Python function return values and Python function return values.

Based on the above knowledge, I believe you have a rough idea about the knowledge points you mentioned today. I cannot elaborate on them here, and it takes a long time to understand them.
After the basic content, you can find more relevant code to view and practice on the machine.

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.