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