Python Note 3

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.