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.