Loading...
Loading...
00:00:00

Numbers in Python

In Python, there are several data types used to represent numbers, including:

  1. Integers (int): Whole numbers such as -2, -1, 0, 1, 2, etc.
  2. Floating-Point Numbers (float): Numbers with decimal points, such as -2.5, 0.0, 3.14, etc.
  3. Complex Numbers (complex): Numbers with real and imaginary components, represented using x + yj where x is the real part and y is the imaginary part.

You can perform various arithmetic operations with these numbers, such as addition, subtraction, multiplication, division, etc.

In Python, you can also convert numbers from one type to another. For example, you can convert an integer to a floating-point number using the float() function or convert a floating-point number to an integer using the int() function.

>>> int(3.14)
3
>>> float(3)
3.0

You can also convert a string representation of a number to an actual number using the int() or float() functions.

>>> int("42")
42
>>> float("3.14")
3.14