← Back to Hub
Module 2 Week 6 • Numbers classification, Int, Float, and Complex

Python Numbers

Study Python numerical types: integers (int), decimals (float), scientific notations, and basic operations.

1. The Three Number Types

Python classifies numbers into three main classes:

  • Integer (int): Whole numbers, positive or negative, of unlimited length. E.g., 10, -999.
  • Float (float): Real numbers containing a decimal point. E.g., 2.5, -8.1. Can also represent scientific numbers with an "e" to indicate power of 10.
  • Complex (complex): Written with a "j" as the imaginary part. E.g., 3+5j. (Useful in advanced physics and graphics programming).

2. Integers vs. Floats

Arithmetic rules dictate how data types convert. Mixing integers and floats in operations automatically converts the result to a float type: 5 + 2.0 yields float 7.0.

💻 Python Code Examples

Example 1: Integer Numbers

x = 1
y = -3579
z = 99999999999
print(type(x), type(y), type(z))

Description: Declares various positive and negative whole numbers, all classified as int.

Example 2: Float Numbers

x = 1.10
y = -35.59
z = 12.0
print(type(x), type(y), type(z))

Description: Declares decimal values. The presence of decimal points yields float types.

Example 3: Scientific Floats

x = 35e3 # 35 * 10^3
y = 12E4
z = -87.7e100
print(x, type(x))

Description: Uses e or E to write scientific power-of-10 numbers, yielding floats.

Example 4: Complex Numbers

c = 3 + 5j
print(c)
print(type(c))

Description: Declares complex numbers using standard algebraic imaginary 'j' notation.

Example 5: Implicit Float Promotion

x = 10
y = 2.5
result = x + y
print(result, type(result))

Description: Adding an integer and a float yields a float type automatically.

Example 6: Exponents Math checks

val = 2 ** 3 # 2^3
print(val, type(val)) # Output: 8, int

Description: Calculates exponents. Integer exponent operations yield integers.

🧠 Active Retrieval Quizzes

Answer the following 10 multiple-choice questions to test your storage strength.

Question 1: Which Python numeric type handles positive or negative whole numbers of unlimited length?

Explanation: In Python, the int type handles integers of arbitrary precision and unlimited size.

Question 2: What data type is the value: 3.14?

Explanation: Decimal values are floating-point values classified as float.

Question 3: What does a scientific float notation like '3e2' represent mathematically?

Explanation: The character 'e' represents scientific notation: 3 * 10^2, which equals 300.0.

Question 4: Which character represents the imaginary part of a complex number in Python?

Explanation: Python uses 'j' (or 'J') to represent the imaginary component of complex numbers.

Question 5: What is the data type result of mixing float and integer: 5 + 3.0?

Explanation: Mixing float and integer operands automatically promotes the result to a float datatype.

Question 6: What data type is: 12E3?

Explanation: Scientific notation (e/E) always yields a float datatype (12000.0).

Question 7: Which of these numbers is classified as a complex type?

Explanation: Complex numbers use 'j' (e.g., 2 + 3j).

Question 8: What is the value of 5.5 // 2 (floor division with float)?

Explanation: Floor division rounds down, but since one operand is a float, the output is float (2.0).

Question 9: What is the data type of the result: 10 // 3?

Explanation: Floor division with two integers yields an integer (3).

Question 10: What does the complex class represent in programming?

Explanation: Complex class represents mathematical complex numbers containing real and imaginary fields.

🖥️ Output Prediction Challenges

Read each code snippet carefully, analyze its execution flow, and predict the exact string result written to the console.

Challenge 1 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(type(5.5))
Console ready. Type your prediction below...
Challenge 2 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(type(3e2))
Console ready. Type your prediction below...
Challenge 3 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(5 + 5.0)
Console ready. Type your prediction below...
Challenge 4 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(type(2 + 4j))
Console ready. Type your prediction below...
Challenge 5 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(10 - 2.0)
Console ready. Type your prediction below...

🎮 Interactive Code Playground

Type your own Python code below and click "Run Code" to execute it instantly in your browser!

📝 Python Code Editor
Python WebAssembly runtime is unloaded. Click 'Run Code' to load.
🖥️ Output Console
Console ready.
💬 Teacher Consultation

Stuck on any concept, or want to explore an edge case? Don't hesitate to ask follow-up questions to your instructor! Active questioning helps build storage strength.

📋 Progress Status

Lesson Complete?

📌 Check the box above to mark this weekend's lesson complete. Your dashboard status ring will update automatically.