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.

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

Python

Tutorials dojo strip

Floating-Point (float)

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

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

Python

Complex (complex)

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

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.

Python

Basic Mathematical Operations

1. Addition (+)

Python

2. Subtraction (-)

Python

3. Multiplication (*)

Python

4. Division (/)

Python

5. Floor Division (//)

Python

6. Modulus (%)

Python

7. Exponentiation(**)

Python

Built-in Mathematical Functions

Python provides several built-in functions for mathematical operations.

1. abs()

Python

2. round()

Python

3. pow()

Python

4. max() and min()

Python

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




Python Labs

Tutorials dojo strip