← Back to Hub
Module 2 Week 5 • Data Type Classification & type() Checks

Core Data Types

Understand Python core primitive types (str, int, float, bool), identify types with type(), and study dynamic transitions.

1. Why Data Types Matter

Computers need to know what kind of data they are working with. You can do math with numbers, but you cannot do math with letters! Python classifies data into specific **Data Types**:

  • String (str): Text values surrounded by quotes. E.g., "Hello" or '123'.
  • Integer (int): Whole numbers without decimals. E.g., 25, -5.
  • Float (float): Decimal numbers containing fractional values. E.g., 8.5, 4.0.
  • Boolean (bool): Logical truth states. Can only be True or False.

2. Checking Data Types using type()

You can check the data type of any value or variable by passing it inside the built-in type() function. It will return the class name of the object (e.g., <class 'str'>).

💻 Python Code Examples

Example 1: Declaring Primitive Types

name = "Ann"    # str
age = 12         # int
score = 95.5     # float
is_happy = True  # bool

Description: Declares variables demonstrating Python's four core primitive types.

Example 2: Using type() function

x = 42
print(type(x))
y = "42"
print(type(y))

Description: Inspects types to show that x is an integer while y is a text string.

Example 3: Division Yields Float

result = 10 / 2
print(result)
print(type(result)) # Output: float

Description: Shows that division operations in Python always return a float datatype.

Example 4: Booleans are Case-Sensitive

# Correct declaration
is_valid = True
# is_valid = true -> throws NameError
print(type(is_valid))

Description: Boolean values must start with capitalized letters (True/False).

Example 5: Floats with trailing zero

val = 5.0
print(type(val)) # Output: float

Description: Even if the fraction is zero, the decimal point makes it a float datatype.

Example 6: Mixing String Quotes

msg1 = "Single 'quote' inside"
msg2 = 'Double "quote" inside'
print(msg1)
print(msg2)

Description: Shows how quotes can be nested inside strings of different quote types.

🧠 Active Retrieval Quizzes

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

Question 1: Which data type represents decimal values in Python?

Explanation: Decimal numbers are floating-point numbers represented by the float type.

Question 2: What class does type('True') return?

Explanation: Because it is wrapped in quotes, 'True' is treated as a text string (str) rather than a boolean literal.

Question 3: Which function is used to query the active data type of a variable?

Explanation: The built-in type() function returns the data type of an object.

Question 4: What data type does the expression x = 4 / 2 return?

Explanation: In Python, the division operator / always returns a float (e.g. 2.0).

Question 5: Which of these is a VALID boolean literal in Python?

Explanation: Python booleans are case-sensitive and must be written as True or False.

Question 6: What data type is the value 100?

Explanation: 100 is a whole number, which Python classifies as an integer (int).

Question 7: What data type is the value 100.0?

Explanation: The decimal point makes 100.0 a float datatype.

Question 8: What is the data type of the value: "25.5"?

Explanation: Quotation marks define text strings (str), even if they contain numbers.

Question 9: What data type is returned by: type(5 > 2)?

Explanation: The comparison expression evaluates to True, which has a boolean (bool) type.

Question 10: Which data type represents simple text characters?

Explanation: Text blocks are represented by the string (str) data type.

🖥️ 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.

x = "Hello"
print(type(x))
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.

x = 10 / 2
print(type(x))
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.

x = 5 > 10
print(type(x))
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.

x = 42
print(type(type(x)))
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.

x = 5.0
print(type(x))
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.