Python Built-in Data Types
In the previous lesson, you learned how to create variables to store information. But have you noticed that different pieces of information come in different forms?
Look at these real-life examples:
- Your name is text (
"Rahul"). - Your age is a whole number (
21). - The price of an item has decimals (
99.50). - Whether you passed an exam is a Yes/No answer (
True).
In programming, the specific category or form of value stored inside a variable is called its Data Type.
1. What are Built-in Data Types?
Python comes with core data types pre-packaged right out of the box. You do not need to install or import anything extra to use them. Because they are native to Python, they are called Built-in Data Types.
Python has 4 fundamental built-in data types:
| Data Type | Keyword | What It Stores | Real-Life Example |
|---|---|---|---|
| String | str | Text, words, and characters | "Hello World", 'Python' |
| Integer | int | Whole numbers (positive, negative, zero) | 25, -10, 0 |
| Float | float | Decimal numbers | 99.50, 3.14, -0.75 |
| Boolean | bool | Logical truth states (True or False) | True, False |
2. Checking Data Types with type()
Python provides a built-in function called type() to inspect the exact data type of any variable:
name = "Rahul"
age = 21
price = 99.50
is_student = True
print(type(name)) # Output: <class 'str'>
print(type(age)) # Output: <class 'int'>
print(type(price)) # Output: <class 'float'>
print(type(is_student)) # Output: <class 'bool'>
💡 Reading the Output: The label inside the quotes (
'str','int','float','bool') tells you the data type of that variable.
3. Why Do Data Types Matter?
Python behaves differently depending on the data type of your values. For example, the + operator changes its behavior based on type:
# With numbers (int / float), + performs mathematical addition
print(10 + 5) # Output: 15
# With strings (str), + joins the text together (concatenation)
print("10" + "5") # Output: 105
print("Think IT " + "Telugu") # Output: Think IT Telugu
Avoiding Type Errors
You cannot directly combine text and numbers using + without converting them first:
# ❌ Causes an error: TypeError: can only concatenate str (not "int") to str
# print("Score: " + 95)
# ✅ Correct: Convert the number to a string using str()
print("Score: " + str(95)) # Output: Score: 95
4. Module 2 Learning Roadmap
Now that you understand what data types are, let's explore each of the 4 fundamental built-in data types in depth across the upcoming lessons:
1. Strings (str)
Learn how to create, join, and format text in Python
2. Numbers (int & float)
Learn whole numbers, decimals, math operators, and type casting
3. Booleans (bool)
Master logical true/false switches and decision flags
Quick Summary
- Data Type: The category of value assigned to a variable (text, numbers, or logic).
- 4 Built-in Types:
str(text),int(whole numbers),float(decimals), andbool(true/false). - The
type()Function: Returns the native data type of any variable. - Type Behavior: Python executes operations based on data types (
+adds numbers, joins strings).
What's Next?
Let's begin with our first fundamental data type: Strings (Text)!