If you’ve ever wondered how Python knows whether a value is a number, some text, or just a simple true or false — you’re about to find out!
Understanding data types in Python is one of those key concepts that makes everything suddenly click when you’re learning to code.
Let’s break this down in the simplest way possible with easy examples and relatable comparisons.
🧩 What Are Data Types in Python?
Every time you create a variable in Python, it stores a certain type of value.
For example:
x = 10
Python needs to know what kind of value x holds — is it a number? Some text? Or something else entirely?
That’s where data types come in.
They tell Python how to treat a particular value — as a number, text, or boolean (true/false).
Depending on the data type, Python decides what operations can be performed on that value.
Let’s explore the most common data types you’ll use all the time.
🔢 1. Integers (int)
Integers are whole numbers — no decimals, just clean counting numbers.
Examples:
age = 25
score = 100
level = -5
All of these are integers. They can be positive, negative, or even zero.
You’ll use integers for things like counting lives in a game, tracking your age, or keeping score.
In simple terms:
No decimal = Integer (int)
🌡️ 2. Floats (float)
Now, floats are numbers with decimals — also known as floating-point numbers.
Examples:
weight = 62.5
temperature = -36.7
price = 99.99
If your value contains a decimal point, Python treats it as a float.
You’ll commonly use floats for:
-
Temperature readings
-
Money and prices
-
Percentages or measurements
In short:
Decimal present = Float (float)
💬 3. Strings (str)
Strings are used to store text — names, sentences, or even emojis!
They’re always enclosed in quotes (single or double).
Examples:
name = "John"
greeting = "Hello, world!"
address = "123 Main Street"
If you forget to put quotes around your text, Python will throw an error because it will assume you’re referring to a variable.
You’ll use strings all the time — for displaying messages, storing user names, working with inputs, and more.
Pro tip:
Anything inside quotes = String (str)
Even numbers written inside quotes (like "100") are treated as strings, not numbers.
✅ 4. Booleans (bool)
Booleans are the simplest of all — they represent True or False values.
They help Python make logical decisions — yes/no, on/off, etc.
Examples:
is_logged_in = True
is_admin = False
game_over = False
You’ll use booleans when you want to check conditions, such as:
-
Is the user logged in?
-
Has the game ended?
-
Is the form submitted?
⚠️ Important: Booleans are case-sensitive.
Always write True and False with a capital first letter.
🧪 Checking Data Types in Python
Sometimes you might not be sure what type of value a variable holds — especially if it’s coming from user input or an external file.
To check, use the built-in type() function.
Example:
x = 42
print(type(x))
Output:
<class 'int'>
If you change it to a string:
x = "42"
print(type(x))
Output:
<class 'str'>
This trick is super helpful when you’re debugging and want to know what’s going on behind the scenes.
Quick Recap
Here’s a summary of what we’ve learned about Python’s main data types:
| Data Type | Example | Description |
|---|---|---|
| int | age = 30 |
Whole numbers (no decimals) |
| float | price = 19.99 |
Numbers with decimals |
| str | name = "Alice" |
Text enclosed in quotes |
| bool | is_active = True |
Logical values (True/False) |
Mastering these four will give you a solid foundation as a beginner Python developer.
Next Step
Now that you understand Python data types, you’re ready to take the next step — learning how to get user input and display output on the screen.
That’s where your code starts becoming interactive and fun!
If you found this blog helpful, don’t forget to bookmark it or share it with a friend who’s just starting their Python journey.
Copyright statement: Unless otherwise indicated, all articles are original to this site, please cite the source when sharing.
Article link:http://pybeginners.com/simplified-python/understanding-data-types-in-python-a-beginners-guide-with-simple-examples/
License agreement:Creative Commons Attribution-NonCommercial 4.0 International License