Day4-python Base-Operator

Source: Internet
Author: User

This section mainly describes the Python operators. To give a simple example 4 +5 = 9 . In the example,4 and 5 are called operands , and "+" is called an operator.

The Python language supports the following types of operators:

    • Arithmetic operators
    • Compare (relational) operators
    • Assignment operators
    • logical operators
    • Bitwise operators
    • Member operators
    • Identity operator
    • Operator Precedence
The following hypothetical variables: a=10,b=20: Arithmetic operations:

Comparison operation:

Assignment operation:

Logical operation:

Member Operations:

Identity operation:

Bit operations:

Example

1 #!/usr/bin/python2 #-*-coding:utf-8-*-3  4A = 60#= 0011 11005b = 13#= 0000 11016c =07  8c = A & B;#0000 11009 Print "the value of the 1-c is:", CTen   Onec = A | b#1101 = 0011 A Print "the value of the 2-c is:", C -   -c = a ^ b;#0001 = 0011 the Print "the value of the 3-c is:", C -   -c = ~a;#-61 = 1100 0011 - Print "the value of the 4-c is:", C +   -c = a << 2;#0000 = 1111 + Print "the value of the 5-c is:", C A   atc = a >> 2;#= 0000 1111 - Print "the value of the 6-c is:"C

The result of the above example output:

The value of the 1-C is: The value of 122-C is: The value of 613-C is: The value of 494-C is: -615-c value is: 15

  

Operator Precedence:

The operators are about this much, more details see HTTP://WWW.RUNOOB.COM/PYTHON/PYTHON-OPERATORS.HTML#YSF1

Day4-python Base-Operator

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.