Basic Data Type Integer, long integer, floating point, plural, string
Variable
You do not need to declare or define a type. You can assign a value when needed.
Function Definition
Def function name (parameter list)
You do not need to declare or define the type when using a variable. Therefore, the function does not need to define the return type.
By default, none is returned.
Notes for Functions
1. the parameter is a value transfer
2. assign values to external variables and use the global keyword
Def Func (x ):
Print ' X is ' , X
X = 2
Print ' Changed local X ' , X
X = 50
Func (X)
Print ' Value of X is ' , X
3. Support for default parameters
Def Say (message, times = 1 ):
Print Message * Times
Say ( ' Hello ' )
Say ( ' World ' , 5 )
4. Key parameters are supported. That is, the parameter of the specified real parameter.
Def Func (a, B = 5 , C = 10 ):
Print ' A is ' ,, ' And B is ' , B, ' And C is ' , C
Func ( 3 , 7 )
Func ( 25 , C = 24 )
Func (C = 50 , = 100 )
Output
>>>
A Is 3 And B Is 7 And C Is 10
A Is 25 And B Is 5 And C Is 24
A Is 100 And B Is 5 And C Is 50
>>>
5. Pass indicates an empty statement block.
Def Somefunction ():
Pass
6. docstrings
If the first logical line after function definition is a string, it is the document string of this function.
The description statement that can be called. The call method isFunction name. _ Doc __
The document string convention is:
A multi-line string whose first line starts with an uppercase letter and ends with a full stop.
The second line is empty,
The detailed description starts from the third line.
Def Printmax (x, y ):
''' This is docstrings.
Return Max number.'''
X = INT (X) # Convert to integers, if possible
Y = INT (y)
If X > Y:
Print X, ' Is maximum '
Else :
Print Y, ' Is maximum '
Printmax ( 3 , 5 )
Print Printmax. _ Doc __