a = 10
b = -5
c = 0
print(a, b, c)10 -5 0
This notebook introduces Python’s built-in number-related types: integers, floats, and complex numbers, along with type conversion, type checking, and small exercises.
int)Integers are whole numbers (positive, negative, or zero) without decimal points.
Examples:
Exercise: Create two integer variables and print their sum.
float)Floats are numbers with decimal points or in scientific notation.
Examples:
3.14159 0.07 -2.5 6.022e+23
Exercise: Create a float variable for temperature and print it in a sentence using an f-string.
complex)Complex numbers have a real and imaginary part, written as a + bj.
Examples:
j for Complex Numbers in Python?In mathematics, the imaginary unit is often written as i. However, in engineering, i is commonly used to represent electric current. To avoid confusion, Python uses j to represent the imaginary unit (√-1).
Example: - 1j means the imaginary number 0 + 1×j. - 2 + 3j means a complex number with real part 2 and imaginary part 3.
(2+3j)
Real part: 2.0
Imaginary part: 3.0
Exercise: Create two complex numbers and multiply them.
Convert between number types using int(), float(), and complex().
Exercise: Convert an integer to a float and a float to an integer, then print the results.
Exercise: Use type() to check the type of a number you define.