Python Day 2 -- operator, python Operator

Source: Internet
Author: User

Python Day 2 -- operator, python Operator

I. Operators

1. Arithmetic Operation:

 

A divided by B a divided by c for division. Number after the decimal point

A // B is used for floor division. Only go to the integer, and remove the number after the decimal point

2. Comparison

 

3. Value assignment

 

4. bitwise operations

Ps: Temporarily unavailable

 

5. logical operations

Note: All data types have boolean values (True/False ). Data with a value of False includes (0, '', None), and all other data is True.

And annotation:

1. in python, and or execute boolean logic computations. They do not return boolean values. Instead, return one of the values for actual comparison.

2. Calculate the value of the expression from left to right in the Boolean context. If all values in the Boolean context are true, and returns the last value.

3. If a Boolean context value is false, and returns the first value

Or annotation:

1. When the or clause is used, the left-to-right calculation is performed in the Boolean context, which is the same as the and clause. However, if either of them is True, or this value is returned immediately

2. If all values are False, or the last False value is returned.

3. Note that or will continue expression calculation in the Boolean context until the first true value is found, and the remaining comparison values will be ignored.

And combined with or:

1. Combined with the previous two syntaxes

2. To enhance program readability, it is best to use it with parentheses, for example:

Ps: Generally, do not write this statement, which is easy to read. But there will be that demand!

 

6. Member operation

Judge the dictionary key value (in only determines the key value)

 

Judgment list (same tuples)

Judge string

 

7. Identity Calculation

 

 

8. Operator priority: top-down, from high to low

 

 

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.