Function
Keyword defining a function: "def":
1 def SayHello (): 2 Print ' Hello world! ' 3 4
It is important to note that the function must already be defined before the function is used, that is, the function call is always after the function is defined.
To define a function with parameters:
1 defSay (message, Times=1, who_say='programe'):2 PrintMessage,who_say * Times3 4Say'Hello')5Say' World', 2)6Say'Hello', who_say='He')
(Note that parameters that do not have a default value cannot be placed after a parameter with a default value)
It's nice to be here. Provides default values for setting parameters, and can be assigned by keyword. This means that, especially in the case of many parameters, you can only assign values to parameters that need to be assigned, rather than having to pass in the preceding arguments because one of the arguments is placed later.
Python is truly natural and easy to read and understand, such as the code just now, you can read the code semantics probably understand that this statement is: Print the message specified number of times
Print message * times
Return statement
You can also use return to end a function in a function, or return a value at the same time. If you do not use the return statement manually, each function will also imply a sentence "return none",none means no value.