Home > Backend Development > Python Tutorial > python basics-operators

python basics-operators

巴扎黑
Release: 2016-12-03 09:57:37
Original
985 people have browsed it

Operators

1. Arithmetic operations: +,-,*,/,%,**,//

print (3+2) => 5print (3-2) => 1print (2*4 ) => 8print (9/3) => 3print (2**2) => 4print (100%51) => 49print (9//2) => 4

2. Comparison operation : ==,!=,<>,>,<,>=,<=

print (3==2) => Falseprint (3!=2) => Trueprint (2< ;>4) => True #has been canceled in python3.5 and integrated into !=print (9>3) => Trueprint (2<2) => Falseprint (100>=51) => Trueprint (9<=2) => False

3. Assignment operations: =,+=,-=,*=,/=,%=,**=,//=

a = 5print (a) => 5a = 5b = 1b += a # b=b+aprint (b) => 6a = 5b = 1b -= a # b=b-aprint (b) => -4a = 5b = 1b * = a # b= b*aprint (b) => 5a = 5b = 1b /= a # b = b/aprint (b) => 0.2a = 5b = 1b **= a # b = b** aprint (b) => 1a = 5b = 1b %= a # b = b%aprint (b) => 1a = 5b = 1b //= a # b = b//aprint (b) => 0

4. Logical calculation: and, or ,not

a = Trueb = Falseprint (a and b) => False # It is true only when a and b are both true print (a or b) => ; True # As long as either a or b is true, it is true print (not a) => False # Not true print (not b) => True # Not false

5. Member operation: in , not in

a = [11,22,33,44]
b = 11
c = 123

print (b in a) =>True
print (c not in a) => True


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template