Lesson 2: Understanding Python Data Types
In this lesson, we’ll explore the different data types in Python — the basic building blocks that determine the kind of values a variable can hold. Understanding data types is essential because they define how data behaves and how you can use it in your programs.
Python’s Core Data Types
- Numbers (integers and floating points)
- Strings (text data)
- Booleans (True or False)
- Lists (collections of items)
2.1 Numbers
Python supports two primary types of numbers: integers (whole numbers) and floating-point numbers (numbers with decimals).
# Integer example
x = 8
print(x) # Output: 8
# Floating point example
y = 24.5
print(y) # Output: 24.5
Tip: You can perform arithmetic operations such as addition, subtraction, multiplication, and division on numeric types.
2.2 Strings
A string represents text and is enclosed in either single (' ') or double (" ") quotes.
# Example of a string
name = "John Doe"
print(name) # Output: John Doe
Strings can contain letters, numbers, and symbols. You can also use built-in string methods to manipulate them, such as converting to uppercase or checking their length.
2.3 Booleans
Booleans are logical values that can only be True or False. They are often used in comparisons and conditions.
x = 5
y = 8
print(x < y) # Output: True
print(y == x) # Output: False
When Python compares two values, it returns a Boolean result — either True if the condition is met or False if not.
2.4 Lists
A list is an ordered collection of items enclosed in square brackets [ ]. Lists can hold strings, numbers, or even other lists.
fruits = ["Orange 🍊", "Mango 🥭", "Apple 🍎", "Grapes 🍇"]
print(fruits)
numbers = [2, 8, 6, 7, 4]
print(numbers)
Each value in a list is called an element. Lists are flexible — you can update them, add new items, or slice them to access specific elements.
Next Lesson
Continue to the next topic to learn more about Python Numbers:
→ Learn About Python NumbersStay connected and continue learning through our official Python learning channel:
FollowExercise
Create your own variables using each data type and print their values. Try changing the data and observing how Python responds!
Quick Quiz
Test Your Knowledge
Want to challenge yourself? Try our interactive quiz on Python Basics!