Python conditional Loop statement

Source: Internet
Author: User

print ' x ', ' Y ' equals

print ' x '

print ' Y '

Output x Y

-------------------------------------------------------------------------------

When importing a function from a module, you can

1, Import Somemodule/ /import module, using function: Module1.open (...)

2, from Somemodule import somefunction//import module function, use function: Open (...), so easy to exist two modules have the same name function, Solution: from module Import function as Anothername, using the Rename method Anotherfunction (...)

3. From somemodule import somefunction,anotherfunction,yetanotherfunction//Importing multiple functions from a module

4, from Somemodule Import *//import module all functions

5. Import Somemodule as Anothername//rename module

--------------------------------------------------------------------------------

Assignment value:

Multiple assignments: x,y,z=1,2,3

>>>values=1,2,3 (Yuanzu value to the variable)

>>>x,y,z=values (Ganso re-assigned to variable, called sequence unpacking)

The number of elements in the sequence unpacking must be exactly the same as the number of variables placed on the left of the assignment symbol =.

Chained assignment: X=y=somefunction ()

Incremental assignment: x *=2

--------------------------------------------------------------------------------

In Python, a colon (:) is used to identify the beginning of a statement block, and each statement in the block is indented, indicating that the current block is closed when it is rolled back to the same indent as the closed block.

False:false None 0 "" () [] {}, itself not equal, that is, False! = None

true: Other

True==1 false==0

Use the bool (name) function to determine what kind of Boolean value to return to TRUE or false.

-------------------------------------------------------------------------------

If num>0:

Xxxxxx

Elif num<0:

Xxxxxx

Else

Xxxxxx

Comparison operators:

X is Y X and Y are the same object
X is not Y X and Y are different objects
X in Y X is a member of the Y container (for example, a sequence)
X not in Y X is not a member of the Y container
X <>y namely X!=y
== Determine if values are equal, single = assignment operator

You can also add and, or, not to join statements in a judgment statement

-------------------------------------------------------------------------------------

Cycle:

While Judgment statement:

Statement block

For variable in sequence:

Statement block

Range (0,10) returns the list from 0 to 9

Iterate through the dictionary elements:

For key in D:

Print key, ' corresponds to ', D[key]

For Key,value in D.items ()://[(x, y), (z,s)] sequence unpacking

Print key, ' corresponds to ', value

Iterative tools:

Zip (names,ages) returns names list and ages list group composition new list [(x, Y), (z,s)]

Jump out of the loop:

Break, jump out of the loop

Continue, skip to the next round of loops

--------------------------------------------------------------------------------------------------------------- ----------

Pass statement: The role of placeholder, do nothing

Del statement: Removing a reference to an object will also remove the name itself, and when a value is no longer used, the Python interpreter is responsible for the memory collection.

EXEC: Executes a string

Eval: Built-in function to evaluate Python expressions for evaluation

Python conditional Loop statement

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.