1. Convert string to numeric
Import locale
Locale. atoi (str)
2. Create a function
A function can be called (may contain parameters) to execute a behavior and return a value.
>>> Import math
>>> X = 1
>>> Y = math. sqrt
>>> Cllable (x)
False
>>> Callable (y)
True
Define a function using def
Def hello (name ):
Return 'hello, '+ name + '! '
In this way, a hello function is defined.
3. Record Functions
Def square (x)
'Calculates the square of the number x .'
Return x * x
The document can be accessed as follows
Square. _ doc _
'Calculates the square of the number x .'
The built-in function help is very useful. You can obtain the function information in the interactive interpreter.
Help (square)
4. Keyword parameters and default values,
5. Collect Parameters
Def print (* param)
* Before the parameter, place all values in a single tuple.
6. Reversal Process
7. Scope
In addition to the global scope, each function creates a scope.
8. Recursion
Function calls are called recursion.