Loading...

Python Numeric Types

Game time scenario

Imagine you’re in charge of updating the scoreboard at a football match. The system needs to track the goals (whole numbers), the average possession percentage (decimals), and whether the game is still active or finished. Not every number is the same!

Python organizes numbers into numeric types, which help the program understand how to work with them.

In this lesson, we’ll build a simplified scoreboard and learn the different numeric types in Python.

Here’s what the scoreboard looks like:

Cricket sports board

You’re the programmer responsible for creating this scoreboard system. Let’s understand the numeric types before we build it.

The core idea

Python has three main numeric types:

  1. Integer (int) – whole numbers without decimals.
    Example: 10, -5, 2025
  2. Float (float) – numbers with decimal points.
    Example: 7.5, 3.1416, 0.99
  3. Complex (complex) – numbers with a real and imaginary part (used in advanced math).
    Example: 2 + 3j

Most beginner projects use int and float. Complex numbers are more common in scientific or engineering problems.

Example in code:

python
3 lines
|
21/ 500 tokens
1
2
3
goals = 3        # int
possession = 62.5  # float
score_formula = 2 + 3j  # complex
Code Tools

Think of our football match:

  • The number of goals must be a whole number (int).
  • The percentage of ball possession is a decimal (float).
  • If we were doing advanced physics modeling for the ball’s motion, we might use complex numbers (complex).

Choosing the right numeric type makes sure our calculations are accurate and logical.

Quick facts

  • int → whole numbers (5, -10, 2024)
  • float → decimals (3.5, 0.01, -7.25)
  • complex → real + imaginary (2+3j, 4-1j)

Try it out

Let’s make a simple football scoreboard:

python
10 lines
|
77/ 500 tokens
1
2
3
4
5
6
7
8
9
10
team_a_goals = 2       # int
team_b_goals = 1       # int
possession_a = 58.5    # float
possession_b = 41.5    # float

print("=== SCOREBOARD ===")
print("Team A Goals:", team_a_goals)
print("Team B Goals:", team_b_goals)
print("Possession A:", possession_a, "%")
print("Possession B:", possession_b, "%")
Code Tools

Output:

text
5 lines
|
23/ 500 tokens
1
2
3
4
5
=== SCOREBOARD ===
Team A Goals: 2
Team B Goals: 1
Possession A: 58.5 %
Possession B: 41.5 %

Work with AI

If you’re using an AI assistant, try this:

Prompt:
Write a Python program that uses integers and floats to create a basketball scoreboard. Include points, fouls, and shooting accuracy (percentage). Print the results clearly.

The AI will generate the scoreboard program with the correct numeric types.

Practice challenge

Great progress! Let’s test your understanding with a new scenario.

Task

Create a scoreboard for a cricket match. Show:

  • Team X runs: 245 (int)
  • Team Y runs: 198 (int)
  • Run rate: 5.75 (float)
  • Target difference: 47 (int)

The output should look like this:

text
5 lines
|
25/ 500 tokens
1
2
3
4
5
=== CRICKET SCOREBOARD ===
Team X Runs: 245
Team Y Runs: 198
Run Rate: 5.75
Target Difference: 47

Solution

python
10 lines
|
65/ 500 tokens
1
2
3
4
5
6
7
8
9
10
team_x_runs = 245
team_y_runs = 198
run_rate = 5.75
target_difference = 47

print("=== CRICKET SCOREBOARD ===")
print("Team X Runs:", team_x_runs)
print("Team Y Runs:", team_y_runs)
print("Run Rate:", run_rate)
print("Target Difference:", target_difference)
Code Tools
Perfect! You’ve now mastered Python’s numeric types and how to use them in real-world projects.

Frequently Asked Questions

Python has three main numeric types: int for integers, float for floating-point numbers, and complex for complex numbers. There's also a bool type, which can be considered numeric since it holds values True or False (1 or 0).

The three main types of numbers in Python are int (integer), float (floating-point number), and complex (complex number).

Yes, Python includes numeric data types like int, float, and complex to represent different kinds of numbers.

Python includes three primary numeric types: int, float, and complex, each serving different purposes.

Numeric data types in Python refer to int, float, and complex, used to represent numbers.

The three types of numbers in Python are int, float, and complex, which store integers, decimal numbers, and complex numbers, respectively.

Numeric characters in Python refer to digits (0-9) used to form numeric values like integers and floating-point numbers.

Still have questions?Contact our support team