Basic Python Tutorial Chapter 5th conditions, loops and other statements reading notes

Source: Internet
Author: User

Fifth chapter: Conditions, loops, and other statements

1. bool (): the BOOL function can return the Boolean type of the argument to true or false.

2. The equality operator is two equals = =.

3. Is is the identity operator.

4. Boolean operator : and,or,not

5. A If B else: If B is true, return a, otherwise, return B.

6. Keyword assert, if the condition must be true , the program will work properly, otherwise an exception occurs.

7. The range function can create a sequence, the first parameter is the lower bound (inclusive), and the second argument is the upper bound (not included).

8. The Xrange function is the same as the range function, but only one number is created at a time.

9. The zip function can turn multiple sequences into a tuple return (which can handle unequal sequences).

10. The keyword break can terminate the entire loop.

11. Keyword continue terminates the current loop, and then begins the next round of loops.

12. List derivation: [X*x for x in range] if x 3 ==0], create a new list by using a different list .

Pass: Do nothing and are useful for unfinished functions and classes.

Del:del keyword Delete is two things, one is the object's reference , and the other is the name of the variable, Del is not deleted value , in Python is There is no way to delete the value, and the Python interpreter is responsible for the memory collection.

The. EXEC: the keyword exec executes the python code stored in the string and can provide the namespace for the EXEC statement. If you print the dictionary scope, all of the built- in functions and values are included.

>>>from Import  = {}>>>exec'sqrt=1' in scope >>>sqrt (4)
2.0>>>sqrt['sqrt']
1

The eval () function : You can evaluate an expression (written as a string), or you can provide a namespace as the keyword exec does.

Basic Python Tutorial Chapter 5th conditions, loops and other statements reading notes

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.