0b
or 0B
0o
or 0O
0x
or 0X
x = 1
y = 882399773218279
z = -125634
a = 0b1100
print(type(x)) # <class 'int'>
print(type(y)) # <class 'int'>
print(type(z)) # <class 'int'>
print(a) # 12
print(type(a)) # <class 'int'>
Output:<class 'int'>
<class 'int'>
<class 'int'>
12
<class 'int'>
Suggested Visuals:E
or e
.23e2
is equivalent to 23 × 10^2
.x = 12.3
y = 12.9829379485794548679
z = -18.96
print(type(x)) # <class 'float'>
print(type(y)) # <class 'float'>
print(type(z)) # <class 'float'>
print(x) # 12.3
print(y) # 12.982937948579455
print(z) # -18.96
Output:<class 'float'>
<class 'float'>
<class 'float'>
12.3
12.982937948579455
-18.96
Suggested Visuals:a + bj
, where a
is the real part and b
is the imaginary part. Note that Python uses j
for the imaginary unit instead of i
.Examples:x = -5j
y = 2 + 4j
z = 22j
print(type(x)) # <class 'complex'>
print(type(y)) # <class 'complex'>
print(type(z)) # <class 'complex'>
Output:<class 'complex'>
<class 'complex'>
<class 'complex'>
Suggested Visuals:int()
– Converts any data type to an integer.float()
– Converts any data type to a float.complex(real, imaginary)
– Converts to a complex number.b = 13.16
c = 2 + 17j
a = 5
# Converting float to int
print(int(b))
# Converting int to float
print(float(a))
# Converting int to complex
print(complex(a))
# Converting float to complex
print(complex(b))
# Converting to complex with real and imaginary parts
print(complex(a, b))
Output:13
5.0
(5+0j)
(13.16+0j)
(5+13.16j)
Suggested Visuals:abs()
– Returns the absolute value.pow()
– Computes power.round()
– Rounds off a number to a given precision.math.sqrt()
– Computes square root (requires importing math
).import math
x = 25
# Absolute value
print(abs(-10))
# Power
print(pow(2, 3))
# Rounding
print(round(12.3456, 2))
# Square root
print(math.sqrt(x))
Output:10
8
12.35
5.0
Suggested Visuals: