a = 10
b = 20
print(a + b)
c = 2**1000
c
a = 4
b = 25
a+b, a-b, a*b, a/b, b/a, b//a, b%a, b**a
# Addition '+'
# Subtraction '-'
# Multiplication '*'
# Division '/'
# Integer (floor) division '//'
# Modulus (remainder division) '%'
# Exponent '**'
See more about operators here
a = 5
b = 20
a == b
# Other comparison operators: <, >, >=, <=, != (not equal), <> (not equal)
Python follows the IEEE 754 for float numbers representation. All floats are represented as 'double precision' numbers which means: 64 bits totally distributed as follows:
- Significand part: 52 bits + 1 bit for sign
- Exponent part: 11 bits
Smaller float: ca. 5.0*1e-324, Largest float: ca. 1.8*1e308
a = 5e3
a+1
b = 1e-1
b+1
x = 13.5
y = 0.8
k = x**y
k
a = 0.1
b = 0.2
a+b
# Why?
See more on float precision here
# 1) Use the 'round()' function
a = 0.1
b = 0.2
print(a+b, round(a+b,2))
# 2) Control not for equality but for "less than an acceptable error"
err = 1e-3
abs((x+y)-0.3) <= err
x = 2.5 + 4j
a = -2
b = 0.5
w = complex(a,b)
x, w
w.real, w.imag
w.conjugate()
import cmath
dir(cmath)
cmath.polar(x)
. Free learning material
. See full copyright and disclaimer notice