Python data types describe the kind of value a name currently points to: number, text, boolean, list, tuple, set, dictionary, or None.
Python keywords are reserved words that already have language meaning. You cannot use them as variable names because Python needs them for syntax.
A strong beginner skill is choosing the right data type before writing more code: one value, many ordered values, unique values, or key-value records.
Python has several built-in data types. Since Python is dynamically typed, the type is determined at runtime based on the value assigned.
| Category | Type | Example |
|---|---|---|
| Text | str | "hello", 'world' |
| Numeric | int, float, complex | 42, 3.14, 2+3j |
| Boolean | bool | True, False |
| Sequence | list, tuple, range | [1,2,3], (1,2) |
| Mapping | dict | {"key": "value"} |
| Set | set, frozenset | {1, 2, 3} |
| Binary | bytes, bytearray | b"hello" |
| None | NoneType | None |
# Numeric types
x = 42 # int
y = 3.14 # float
z = 2 + 3j # complex
print(type(x)) # <class 'int'>
print(type(y)) # <class 'float'>
print(type(z)) # <class 'complex'>
# String
name = "Python"
print(type(name)) # <class 'str'>
# Boolean
is_active = True
print(type(is_active)) # <class 'bool'>
# None (absence of value)
result = None
print(result is None) # True
# Sequence types
my_list = [1, 2, 3] # mutable
my_tuple = (1, 2, 3) # immutable
my_range = range(1, 10, 2) # 1,3,5,7,9
# Mapping
person = {"name": "Alice", "age": 25}
# Set
unique = {1, 2, 3, 2, 1} # {1, 2, 3}
# int - unlimited precision
big = 123456789012345678901234567890
print(big)
# float - 64-bit double precision
pi = 3.141592653589793
sci = 1.5e10 # scientific notation = 15000000000.0
# complex
c = 3 + 4j
print(c.real) # 3.0
print(c.imag) # 4.0
print(abs(c)) # 5.0 (magnitude)
# Useful numeric functions
print(abs(-7)) # 7
print(round(3.567, 2)) # 3.57
print(pow(2, 10)) # 1024
print(divmod(17, 5)) # (3, 2) - quotient and remainder
Keywords are reserved words that have special meaning in Python. You cannot use them as variable names, function names, or identifiers.
import keyword
print(keyword.kwlist)
# Python 3 keywords:
# False await else import pass
# None break except in raise
# True class finally is return
# and continue for lambda try
# as def from nonlocal while
# assert del global not with
# async elif if or yield
# True, False, None
flag = True
empty = None
# and, or, not
print(True and False) # False
print(True or False) # True
print(not True) # False
# in, not in - membership test
fruits = ["apple", "banana"]
print("apple" in fruits) # True
print("mango" not in fruits) # True
# is, is not - identity test
x = None
print(x is None) # True
print(x is not None) # False
# del - delete a variable
temp = 42
del temp
# print(temp) # NameError: name 'temp' is not defined
# pass - keep a block intentionally empty
def handle_later():
pass # add the body when the behavior is known
# assert - debugging check
age = 20
assert age >= 0, "Age cannot be negative"
0 of 2 checked
Try this next
0 of 2 completed
Use type(value) while learning or debugging. In real logic, prefer behavior checks and clear conversion at input boundaries.
They are Python keywords. Python reserves them for syntax, so using them as names would make code ambiguous.
Start with lists for ordered values and dictionaries for named values. Then learn tuples for fixed records and sets for unique membership.
Explore 500+ free tutorials across 20+ languages and frameworks.