Python Note 2

Source: Internet
Author: User

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)

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.