Python Arithmetic Operations
kodingwindow@kw:~$ python3
...
>>> 10+20
30

>>> 10-20
-10

>>> 10*20
200

>>> 2**10
1024

>>> 10/20
0.5

>>> 10//20
0

>>> 7%4
3

>>> 7^4
3

>>> -7^4
-3
Arithmetic operations on complex numbers
>>> c1=4+5j
>>> c2=2+6j

>>> print(c1+c2)
(6+11j)

>>> print(c1-c2)
(2-1j)

>>> print(c1*c2)
(-22+34j)

>>> print(c1/c2)
(0.95-0.35000000000000003j)
Swap the given numbers
>>> a=10
>>> b=20
>>> a=a+b
>>> b=a-b
>>> a=a-b
>>> a
20

>>> b
10

>>> a=10 >>> b=20 >>> (a,b)=(b,a) >>> a 20 >>> b 10
Advertisement