What are the Arithmetic Operators in Python

Get to know Arithmetic Operators

The following table lists the arithmetic operators in Python.

Operator Expression Meaning
** expr1 ** expr2 expr1 raised to the power of expr2[a]
+ +expr (unary) expr sign unchanged
- -expr (unary) negation of expr
* expr1 * expr2 expr1 times expr2
/ expr1 / expr2 expr1 divided by expr2 (classic or true division)
// expr1 // expr2 expr1 divided by expr2 (floor division [only])
% expr1 % expr2 expr1 modulo expr2
+ expr1 + expr2 expr1 plus expr2
- expr1 - expr2 expr1 minus expr2

Here are a few more examples of Python's numeric operators:


print -442 - 77# w  ww. j  a v  a2 s.c o m
print 4 ** 3
print 4.2 ** 3.2
print 8 / 3
print 8.0 / 3.0
print 8 % 3
print (60. - 32.) * ( 5. / 9. )
print 14 * 0x04
print 0170 / 4
print 0x80 + 0777
print 45L * 22L
print 16399L + 0xA94E8L
print -2147483648L - 52147483648L
print 64.375+1j + 4.23-8.5j
print 0+1j ** 2          # same as 0+(lj**2)
print 1+1j ** 2          # same as 1+(lj**2)
print (1+1j) ** 2

The code above generates the following result.





















Home »
  Python »
    Language Basics »




Python Basics
Operator
Statements
Function Definition
Class
Buildin Functions
Buildin Modules