In Python (programming language), data types define the type of value a variable can store. Every variable in Python holds data of a specific type, such as numbers, text, or collections of data.
Python automatically determines the data type based on the value assigned to a variable.
Example:
x = 10
name = "Alice"
price = 5.5
Here Python automatically assigns the correct data type.
π¦ Common Python Data Types
1οΈβ£ Numeric Types
Numeric data types store numbers.
Integer (int)
Whole numbers without decimals.
Example:
age = 25
year = 2026
Float (float)
Numbers with decimal points.
Example:
price = 19.99
temperature = 36.5
Complex (complex)
Numbers with a real and imaginary part.
Example:
x = 3 + 4j
π€ String (str)
Strings store text data.
Strings are written inside single or double quotes.
Example:
name = "Rahul"
message = 'Hello Python'
βοΈ Boolean (bool)
Boolean data types store True or False values.
Example:
is_student = True
is_logged_in = False
Booleans are commonly used in conditions and comparisons.
π Sequence Types
List (list)
A list stores multiple values in a single variable and is changeable.
Example:
fruits = ["apple", "banana", "mango"]
Tuple (tuple)
A tuple also stores multiple values but cannot be changed after creation.
Example:
coordinates = (10, 20)
π’ Set (set)
A set stores unique values and does not allow duplicates.
Example:
numbers = {1, 2, 3, 4}
π Dictionary (dict)
A dictionary stores data in key-value pairs.
Example:
student = {
"name": "Rahul",
"age": 21,
"course": "Python"
}
π§ͺ Checking Data Types
You can check the type of a variable using the type() function.
Example:
x = 10
print(type(x))
Output:
<class 'int'>
β Summary of Python Data Types
| Data Type | Example |
|---|---|
| int | 10 |
| float | 10.5 |
| complex | 3+4j |
| str | “Hello” |
| bool | True |
| list | [1,2,3] |
| tuple | (1,2,3) |
| set | {1,2,3} |
| dict | {“name”:”Rahul”} |
β Understanding data types is essential because they determine how data behaves in Python (programming language) programs.