Data Types in Python: Complete Guide with Examples
Python supports several built-in data types, each designed for specific kinds of information. Understanding them is foundational to writing efficient Python code. This guide covers all of them ÔÇö numeric, sequence, mapping, set, boolean, and NoneType ÔÇö with practical examples.
Complete Python Course:-
Complete Advance AI topics:-
1. Numeric Types
age = 25 # int ÔÇö whole number
pi = 3.14159 # float ÔÇö decimal
z = 2 + 3j # complex ÔÇö real + imaginary
a, b = 5, 2.5
c = a + b
print(c) # 7.5
2. Sequence Types
# String
greeting = "Hello, World!"
# List ÔÇö ordered, mutable
fruits = ["apple", "banana", "cherry"]
# Tuple ÔÇö ordered, immutable
coordinates = (10.0, 20.0)
# Range ÔÇö sequence of numbers
r = range(1, 10)
3. Mapping Type (Dictionary)
student = {"name": "John", "age": 21, "major": "CS"}
print(student["name"]) # John
student["age"] = 22 # update
print(student)
4. Set Types
# set ÔÇö mutable, unique items, unordered
colors = {"red", "green", "blue"}
# frozenset ÔÇö immutable
vowels = frozenset(["a", "e", "i", "o", "u"])
set1, set2 = {1, 2, 3}, {3, 4, 5}
print(set1 | set2) # union: {1, 2, 3, 4, 5}
5. Boolean Type
is_adult = True
is_student = False
print(is_adult and is_student) # False
6. NoneType
data = None
if data is None:
print("No data available")
Mutable vs Immutable
- Mutable: list, dict, set ÔÇö can be changed in-place.
- Immutable: int, float, str, tuple, frozenset ÔÇö cannot be changed.
Check Type with type()
x = 42
print(type(x)) # <class 'int'>
print(isinstance(x, int)) # True
Download New Real Time Projects:- Click here
Conclusion
Python data types are flexible and intuitive. Master int, float, str, list, dict, set, and bool ÔÇö and you can handle virtually any data manipulation. For more guides, stay tuned to .
data types in python
immutable data types in python
mutable data types in python
primitive data types in python
basic data types in python
data types in python with examples
different data types in python
python data types w3schools