The Python operator includes
- Assignment operator (=)
- Arithmetic operators (+ 、-、 *,/,//,%, power (two asterisks))
- Relational operators (<, >, <=, >=,! =, = = (exactly equals))
- logical operators (and, or, not)
An expression
is a formula that connects different data (including variables, functions) with the operator by a certain rule.
Attention
- "/" division. If the action is evenly divisible on the integer type, it is normal division if it is acting on a floating-point type.
- "//" integer Division (floor division). As follows:
>>> 5.6/22.8>>> 5.6//22.0>>> 5.6//2.82.0
- "* *": Operation of Power
>>> 3**29>>> 2**38
- "+ =", "-=", "*=", "/=" 、、、
>>> 1<2True>>> 2<1False>>> 1!=2True>>> 1==1True>>> 1==1.0True
Precedence of Operators
From top to bottom is from low to high
Simple arithmetic device
1 #!/usr/bin/python 2 3 a = int (raw_input (" Please input NUM1: ")) 4 #raw_input () return str type! 5 b = int (raw_input ()) 6 7 print A + b 8 print A-9 print A * b 10 print A/b
运行结果:~ python computer.pyplease input num1:12num2:21410246
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Middle Valley Education python operators and expressions