First, the function
1. Define function: def function name ():
2. Calling function: The name of the direct write function ()
>>> def myfirstfunction ():
Print (' This my first function ')
Print (' I'm excited .... ‘)
>>> myfirstfunction ()
This my first function
I am very excited ....
>>>
3. Parameters of the function
>>> def myfirstfunction (name):
Print (name+ ' I love you! ‘)
>>> myfirstfunction (' dusty ')
Dust-laden I love you!
>>>
To set multiple parameters, just separate them with commas
>>> def Add (num1,num2):
result = Num1+num2
Print (Result)
>>> add
3
>>>
Second, exercises
1. What is dry
It is emphasized that the same code should not be repeated when programming, it is best to write it only once, and then it can be referenced elsewhere. The advantage is that you can increase the code reuse rate, reduce the amount of code, and also help improve the readability and maintainability of your code. When you need to make changes, you only need to change one place
2. Can a function have more than one parameter?
Theoretically yes, except that if the function has too many parameters, the chance of error will be greatly improved when the call is called, preferably a thin parameter
3. What keywords to use to create functions, and what to pay attention to
Keywords: def It is important to note that the function name is preceded by a parenthesis and a colon
"python017--function Object 1"