All functions defined in class are method, including _ init __. each method has at least one parameter self, which is equivalent to this in C ++. The variables declared in the class are attributes, which can be added or deleted at any time.
Inheritance: class <Name> (superclass1, superclass2 ,...).
Special Method in class:
_ Init __
_ Del _ (Self): it is called when an object is deleted.
_ Repr _ (Self): called when the Repr function is used
_ STR _ (Self): returns a string to describe the object itself.
_ CMP _ (self, other): A comparison operator with 0 equal, 1 greater than,-1 less
_ Nozero _ (Self ):
_ Len _ (Self): the length of the returned object when Len () is called.
_ Getitem _ (self, key): return self [Key], used to simulate data structures such as list
_ Setitem __: (self, key, value) simulate OBJ [Key] = Value
_ Delitem _ (self, key): Simulate del OBJ [Key]
_ Contains _ (self. Other): Processes in statements.
_ Call _ (self, arg1, arg2,...): allows OBJ to be called like a function.
There are also many Arithmetic Operators. You can refer to the python reference manual.
Exception Handling:
Capture exceptions:
Try:
...
Except t exceptiontype:
...
Else:
...
Or
Try:
...
Finally:
...
An exception is thrown using the raise statement.
Import a module
RunCode: Exec code [IN glocaldict, [, localdict]
System-related calls are used in sys with import sys.
OS-related calls are used in the OS by using the import OS.
Platform independence should be written using OS. PathProgramPath encapsulates the path Representation Methods on each platform.
Open the file with F = open ("FILENAME", "R"), R can use R-read-only, W-write only, RW-read/write, Rb-Read Binary, WB-write binary data.
The cmd module can be used to easily compile command line interfaces.
AvailableC LanguageCompile Python extension modules.