Loop Structure:
for x in <sequence>:
<statement-block>
else:
<else-block>
while <expr1>:
<block>
else:
<else-block>
Function:
def <function_name>(<parameters_list>):
<code-block>
The function has no return value type. Return can return any type. The function name is just a variable, an object, which assigns a function name to another variable. This is a bit like a function pointer. Data is called a function alias.
Function parameters can be default values like C ++.
As defined below:
def printf(format,*arg):
...
The number of parameters can be changed. * Arg indicates that any parameter can be accepted, just like printf in C. Arg is a tuple, which can be accessed as a tuple access method.
Function Description: if the first expression of a function is a string, it becomes the _ Doc _ of the function __.
Lambda functions are equivalent to anonymous functions.
You can use nested functions.
Module. A module stores some functions and classes in A. py file.
A package is a set of modules.
Namespace:
Class:
class class_name
...
You can define a Def _ init _ (Self) function in the class. Python does not have constructor or destructor, but init is automatically called when an object is created. Classes are objects like functions, so classes can be assigned to common variables.
The function defined in the class is the method. The method must have at least one parameter self, which is equivalent to this in C ++.
The variables defined in the class are attributes that can be created and deleted at any time.
Inheritance: class <Name> (superclass1, superclass2)