Geek Slack

Start creating your course and become a part of GeekSlack.

Introduction to Python
About Lesson



Python Numbers


Python Numbers

Python supports various types of numbers, including integers, floats, and complex numbers. In this chapter, we’ll explore these types and see examples of how to use them in Python.

1. Integers

Integers are whole numbers, both positive and negative, without any decimal points.

Example:

x = 5
y = -10
z = 0

2. Floats

Floats, or floating-point numbers, represent real numbers with a decimal point or exponent notation.

Example:

x = 3.14
y = -0.5
z = 2.5e2

3. Complex Numbers

Complex numbers consist of a real part and an imaginary part, represented as a + bi, where a is the real part and b is the imaginary part.

Example:

x = 3 + 4j
y = complex(5, -2)

4. Number Operations

Python supports various arithmetic operations on numbers, including addition, subtraction, multiplication, division, exponentiation, and modulus.

Example:

a = 10
b = 3

addition = a + b
subtraction = a - b
multiplication = a * b
division = a / b
exponentiation = a ** b
modulus = a % b

Conclusion

Numbers are an essential part of programming, and Python provides robust support for various types of numbers, including integers, floats, and complex numbers. Understanding how to work with numbers in Python is crucial for developing a wide range of applications.

Join the conversation