There are three numeric types in Python:
intfloatcomplexVariables of numeric types are created when you assign a value to them:
x = 1 # int y = 2.8 # float z = 1j # complexprint(type(x)) print(type(y)) print(type(z))
int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
x = 1 y = 35656222554887711 z = -3255522
float, or "floating point number" is a number, positive or negative, containing one or more decimals. Floats can also be scientific numbers with an "e" to indicate the power of 10.
x = 1.10 y = -87.7e100
Complex numbers are written with a "j" as the imaginary part. They are mostly used in advanced mathematical computing.
x = 3+5j y = 5j
You can convert from one type to another with the int(), float(), and complex() methods. Note: You cannot convert complex numbers into another number type.
Which letter is used to represent the imaginary part of a complex number in Python?