In Python, numbers are a basic data type used for mathematical operations, calculations, and data processing. Python supports three main numeric types: integers, floating-point numbers, and complex numbers. You can easily convert between these types and use built-in numeric functions to perform common tasks.
int) represent whole numbers like 10, -25.float) represent decimal numbers like 3.14, -0.001.complex) represent numbers with a real and imaginary part like 2+3j.type() function.int(), float(), and complex().abs(), pow(), and round() for common numeric operations.Python automatically assigns a numeric type based on the value you write:
x = 5 → x is of type int.y = 3.14 → y is of type float.z = 2 + 3j → z is of type complex.For complex numbers, you can access:
z.real → the real part (as a float).z.imag → the imaginary part (as a float).Type conversion allows you to change values from one numeric type to another using constructor functions: int(), float(), and complex().
x = 5 # int
y = 3.14 # float
z = 2 + 3j # complex
print(type(x))
print(type(y))
print(type(z))
z = 2 + 3j
print(z.real) # 2.0
print(z.imag) # 3.0
a = float(5)
b = int(4.8)
c = complex(3)
print(a, b, c)
print(abs(-10)) # 10
print(pow(2, 3)) # 8
print(round(3.7)) # 4
<class 'int'>, <class 'float'>, and <class 'complex'>, confirming the type of each variable.z.real gives 2.0 and z.imag gives 3.0, which are the real and imaginary parts of 2+3j.a becomes 5.0 (float), b becomes 4 (int, decimal part removed), and c becomes (3+0j) (complex number with zero imaginary part).abs(-10) returns 10 (distance from zero).pow(2, 3) returns 8 (2 raised to the power 3).round(3.7) returns 4 (nearest integer).type() often to check what kind of number (int, float, complex) you are working with.float when working with division or values that require decimals.int() truncates the decimal part (for example, int(4.9) becomes 4, not 5).abs() when you need the magnitude of a number regardless of sign.pow(x, y) is equivalent to x ** y and can sometimes be clearer to read.int using int(), and print both values.5+2j and print its real and imaginary parts using .real and .imag.pow() to calculate 3**4 and verify the result with manual multiplication.round() on different floats, such as round(3.2), round(3.5), and round(3.8).