Python Numbers

Python supports three main types of numbers: integers, floating-point numbers, and complex numbers. Each type has its own characteristics and uses. Python also provides various built-in functions and operators to perform mathematical operations.


Integer (int)

Integers are whole numbers, both positive and negative, without a decimal point.

Explanation of Code:

x is a positive integer, and y is a negative integer.

Tutorials dojo strip




Floating-Point (float)

Floating-point numbers are real numbers with a decimal point. They can also be represented in scientific notation.

Explanation of Code:

a and b are floating-point numbers, while c is a floating-point number represented in scientific notation.




Complex (complex)

Complex numbers have a real part and an imaginary part, and they are written in the form a + bj.

Explanation of Code:

d is a complex number with a real part 2 and an imaginary part 3j. e is another complex number created using the complex() function.




Basic Mathematical Operations

1. Addition (+)


2. Subtraction (-)


3. Multiplication (*)


4. Division (/)


5. Floor Division (//)


6. Modulus (%)


7. Exponentiation(**)




Built-in Mathematical Functions

Python provides several built-in functions for mathematical operations.

1. abs()


2. round()


3. pow()


4. max() and min()




Python Numbers Example Code

Explanation of Code:

This program declares several variables and performs various mathematical operations using both operators and built-in functions. The results are printed to the console.




Python Labs

Tutorials dojo strip