What is a function?
function is derived from mathematics, but the concept of "function" in programming is very different from the function in mathematics, the specific difference, we will say later, the function of programming in English also has a lot of different names. In basic it is called subroutine (sub-process or subroutine), in Pascal is called procedure (process) and function, in C only function, in Java is called method.
Definition: A function that encapsulates a set of statements by a name (function name), and to execute the function, simply call the name of its functions
Characteristics:
Reduce duplicate code
To make the program extensible
Make programs easier to maintain
Syntax Definitions:
def name ():# function name print("Hello, I ' m yue! " # Call function
Also available with parameters:
A B =a**bprint# is changed to write def Calc (x, y) with a function: = x**y return# returns function execution result = Calc (A, B) # result assigned to c variable Print(c)
Basic syntax and characteristics of python-function