Python Data Types Guide for Beginners
1. Numeric Types
int: Whole numbers. Example: 5, -10.
float: Decimal numbers. Example: 3.14, -0.001.
complex: Numbers with real and imaginary parts. Example: 2 + 3j.
Usage Examples:
# int
a = 10
# float
b = 3.14
# complex
z = 2 + 3j
print([Link], [Link])
2. Sequence Types
str: Text. Example: 'Subhan'.
list: Mutable collection. Example: [1, 2, 3].
tuple: Immutable collection. Example: (1, 2, 3).
range: Sequence of numbers. Example: range(5).
Usage Examples:
name = "Subhan"
fruits = ["apple", "banana"]
colors = ("red", "green")
for i in range(5):
print(i)
3. Set Types
set: Mutable collection of unique elements. Example: {1, 2, 3}.
frozenset: Immutable set. Example: frozenset({1, 2, 3}).
Usage Examples:
numbers = {1, 2, 3}
[Link](4)
fs = frozenset([1,2,3])
4. Mapping Type
dict: Key-value pairs. Example: {'name': 'Subhan', 'age': 18}.
Usage Examples:
person = {"name": "Subhan", "age": 18}
print(person["name"])
5. Boolean Type
bool: True or False.
Usage Examples:
a = 10
b = 5
print(a > b) # True
6. Binary Types
bytes: Immutable bytes. Example: b'hello'.
bytearray: Mutable bytes. Example: bytearray(b'hello').
memoryview: Access binary data efficiently.
Usage Examples:
b = b"hello"
ba = bytearray(b"hello")
mv = memoryview(b"hello")
7. None Type
NoneType: Represents no value. Example: None.
Usage Examples:
x = None
if x is None:
print("No value assigned")
Tips for Beginners: - Use parentheses () for range() and square
brackets [] for lists. - Strings require quotes " or '. - Tuples are
immutable, so you cannot change elements. - Sets remove duplicates
automatically. - Dictionaries store key-value pairs for fast lookup.