Editor settings

General settings

Save settings

Learn to program with Python

Numbers in Python #

Python provides several built-in numeric data types, including integers, floating-point numbers, and complex numbers.

Integers #

Integers are whole numbers that can be positive, negative, or zero. In Python, integers are represented by the int data type. You can use integers to represent counts, scores, and other discrete values in your programs. For example:

# Example of integers
x = 5
y = -3
z = 0

Floating-Point Numbers #

Floating-point numbers are numbers with a decimal point that can be positive, negative, or zero. In Python, floats are represented by the float data type. You can use floats to represent measurements, ratios, and other continuous values in your programs. For example:

# Example of floating-point numbers
x = 3.5
y = -2.25
z = 0.0

Complex Numbers #

We won't be using complex numbers in this course and rarely in real-life scenarios. You can skip complex numbers if you'd like.

Complex numbers have both a real and an imaginary part.

# Example of complex numbers
x = 2 + 3j
y = -1 - 4j
z = 0 + 2j

Exercise #

  • Create a variable x and assign an integer to it.
  • Create a variable y and assign a float number to it.
Output will be displayed here