Basic Python Tutorial (5)

Source: Internet
Author: User

5.2 Assignment Magic:

5.2.1 Sequence Unpacking: It allows the function to return more than one value and package the Narimoto group, which is then easily accessible through an assignment statement. The number of elements in the unpacked sequence must be exactly the same as the number of variables placed on the left of the assignment symbol =, otherwise an exception will occur.

5.2.2 Chain Assignment: Assign a value to multiple variables.

5.2.3 Increment Assignment: +=,*=

5.3 Indent:

5.4 Items and Conditional statements:

False: false,none,0, "", (), [],{}.

Conditional execution And if statement, Else statement, Elif statement

To sum up: use the = = operator to determine whether two objects are equal, using is to determine whether the two are equal (the same object).

Assertion (Assert): If you need to make sure that a condition in your program must be true for your program to work, it can place checkpoints in your program. After a condition, you can add a string to interpret the assertion.

5.5 Cycles:

Some iterative tools: 1, parallel iteration (Zip function), zip can cope with unequal sequences, when the shortest sequence runs out of time will stop.

The range function creates an entire sequence at a time, and the Xrange function creates one number at a time.

2, number iteration (enumerate function)

3. Flip and sort iterations (reversed and sorted), instead of modifying the object in situ, return the flipped or sorted version

Jump out of the loop: 1, break

2, continue, let the current iteration end, "Jump" to the beginning of the next round of the cycle. That is, "skips the remaining loop body, but does not end the loop."

5.6 List Derivation:

5.7 Threesome:1, nothing happened (pass)

2. Delete by using Del, delete only the name, not the list itself.

3. Execute and evaluate strings using exec and eval: 1. The statement executing a string is exec

2. Eval evaluates the Python expression (written in string)

Basic Python Tutorial (5)

Related Article

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.