This content originally appeared on DEV Community and was authored by obonyodorice
Hey Everyone! Learning Python's Basic "Building Blocks"#
When I started learning Python, I just wanted to make my computer do cool things. But sometimes, my code didn't work right. I wondered: How does the computer know if "5" is a number or just a word?
Then, I learned about Python Data Types. This was a big moment for me! It's how Python understands what kind of "stuff" you're giving it. Like, is it text? Is it a number? Is it a list of things?
In this story, I'll share how I learned about these basic types of "stuff" in Python. I'll use super easy examples to show you what clicked for me.
My Secret Trick: Asking Python "What Are You?" (type()
function)
First, I found a cool trick: the type()
tool. It lets you ask Python directly, "What kind of data is this?"
my_age = 30
my_name = "Dorice"
is_happy = True
print(type(my_age))
print(type(my_name))
print(type(is_happy))
What you'd see:
<class 'int'> # Python says: This is a WHOLE NUMBER."
<class 'str'> # Python says: "This is TEXT."
<class 'bool'> # Python says: "This is a TRUE/FALSE."
This simple trick showed me that Python always knows what type of "stuff" it has. This is key to making your code work right!
The Main Types of "Stuff" in Python (What I Learned!)
Let's look at the basic types and my simple take on them:
1. Numbers (int
and float
): For Counting and Math
Numbers are for math. Python has two main kinds:
- Whole Numbers (
int
): Numbers without decimals.
Like: 5, 100
I use them for: Counting things (apples, people).
apples = 5
print(f"I have {apples} apples.")
- Decimal Numbers (float): Numbers with decimals.
Like: 3.14, 19.99
I use them for: Prices, measurements (like temperature).
price = 19.99
print(f"The price is ${price}.")
2. Text (str
): For Words and Sentences
Strings are for any words or sentences. Put them in quotes ("..."
or '...'
).
- Like:
"Hello"
,'My name is Dorice'
- I use them for: Names, messages, anything you want to read.
- What I learned: You cannot change parts of a string after you make it. If you add to it, Python makes a new string.
my_greeting = "Hi!"
print(my_greeting)
greeting = my_greeting + " How are you?"
print(greeting)
3. True/False (bool
): For Yes/No Questions
Booleans are super simple: they are either True
or False.
They help your code make choices.
Like: True
,False
(always starts with a capital letter!)
I use them for: Asking questions like "Is it sunny?" or "Is the game over?"
is_sunny = True
if is_sunny:
print("Go play outside!")
else:
print("Stay inside.")
- Lists (
list
): Lists are like a shopping basket. They hold items in an order, and you can change them anytime.
-
Like:
["milk", "bread", "eggs"]
,[1, 2, 3]
- I use them for: Shopping lists, a list of tasks.
- What I learned: Lists are changeable! I can add, remove, or change items easily.
my_basket = ["apple", "banana"]
print(f"My basket: {my_basket}")
my_basket.append("orange") # Add an item
print(f"Basket now: {my_basket}")
5. Tuples (tuple
): The "Fixed" Container
Tuples are like lists, but with one big rule: once you make them, you cannot change them. They are set in stone.
Like: (10, 20)
(for a map point that shouldn't move)
I use them for: Things that must stay exactly the same.
What I learned: If I want data that stays fixed, I use a tuple. Trying to change it gives an error!
dorice_birthday = (27, 6, 1996) # Using an example birth year for Dorice
print(f"Dorice's birth day is the {dorice_birthday[0]}th.") # Get the first item (day)
print(f"Dorice's birth month is {dorice_birthday[1]}.")
print(f"Dorice's birth year is {dorice_birthday[2]}.")
print(f"Type of dorice_birthday: {type(dorice_birthday)}") # Shows <class 'tuple'>
6. Sets (set
): My "Only Unique Items" Collector
Sets are cool because they only store unique items. If you try to put a double in, it just ignores it. Also, they don't keep things in order.
-
Like:
{1, 2, 3}
,{"red", "blue"}
- I use them for: Finding all the different items in a group.
- What I learned: Great for quickly finding unique things or if I don't care about the order.
my_numbers = {1, 2, 3, 2, 4} # '2' is repeated
print(f"Unique numbers: {my_numbers}") # Shows {1, 2, 3, 4} (no repeats!)
my_numbers.add(5) # Add a new one
print(f"New list: {my_numbers}")
7. Dictionaries (dict
): The "Label and Value" Box
Dictionaries are like a box where you put items with labels. You have a "label" (called a key) and the "item" itself (called a value).
-
Like:
{"name": "Dorice", "age": 28}
- I use them for: Storing details about a person (like their name, age, city).
- What I learned: Super easy to find info using its label, and I can change or add things easily.
my_details = {
"name": "Dorice",
"age": 28,
"city": "Mombasa"
}
print(f"My name is: {my_details['name']}") # Find 'name'
print(f"My age is: {my_details['age']}") # Find 'age'
my_details["age"] = 29 # Change age
print(f"My new age: {my_details['age']}")
My Big Idea: "Changeable" vs. "Unchangeable"
This was the trickiest part, but it made everything click:
-
Changeable (
list
,set
,dict
): You can change them after you make them. -
Unchangeable (
int
,float
,str
,bool
,tuple
): If you try to "change" them, Python actually just makes a new one. They stay fixed.
Understanding this helps you avoid confusing problems in your code!
Why This Matters to Me Now: Coding Is Fun!
Learning these basic "types of stuff" made coding much clearer for me. Now, I:
- Pick the right tool: I know if I need a basket (list) or a label box (dictionary).
- Write better code: My code works more smoothly.
- Fix problems faster: If something breaks, I can guess what type of "stuff" is causing the issue.
It's not just about memorizing names. It's about helping Python understand what you want to do with your information, so it can build awesome things for you!
Keep Learning, Keep Building!
I hope my simple story helps you with Python's data types. Just keep trying the examples and playing with them! That's how I learn best.
What was your big "aha!" moment in coding? Let me know in the comments!
This content originally appeared on DEV Community and was authored by obonyodorice

obonyodorice | Sciencx (2025-06-27T07:35:00+00:00) How I Finally “Got” Python Data Types!. Retrieved from https://www.scien.cx/2025/06/27/how-i-finally-got-python-data-types/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.