agyanadda@gmail.com

Python Data Types

Python Basics 1 min read Updated Dec 4, 2026 Topic 5 of 32

Every value in Python has a type. Check it with type() or isinstance().

Category Types Example
Text str "hello"
Numbers int, float, complex 10, 3.14, 2+3j
Boolean bool True, False
Sequences list, tuple, range [1, 2], (1, 2)
Set set, frozenset {1, 2}
Mapping dict {"a": 1}
Nothing NoneType None
Binary bytes b"hi"

Mutable vs immutable

  • Immutable (cannot be changed in place): int, float, str, tuple, bool
  • Mutable (can be changed): list, dict, set

This matters when two variables refer to the same list — changing one changes both.

None

None means "no value". Check it with is None, not == None.

Truthy and falsy

These count as False in an if: 0, 0.0, "", [], {}, set(), None. Everything else is True.

Example

Example — Types and mutability Python
items = [10, "pen", 2.5, True, None, (1, 2), {"a": 1}]
for item in items:
    print(repr(item), "->", type(item).__name__)

# Mutable list shared by two names
a = [1, 2, 3]
b = a
b.append(4)
print("a:", a)            # a changed too!

c = a.copy()               # independent copy
c.append(5)
print("a:", a, "c:", c)

print(isinstance(3.5, float))
print(bool(""), bool("0"), bool([]))

Lists each type name (int, str, float, bool, NoneType, tuple, dict). a becomes [1, 2, 3, 4] because b is the same list; the copy c is separate. Last line: False True False.

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which type is immutable?

Exercise 2 True / False

An empty list [] is treated as False in an if statement.

Exercise 3 Fill in the Blank

Check for no value with: if x is ___

Frequently Asked Questions

Assignment like b = a does not copy; both names point to the same list. Use a.copy(), list(a) or a[:] for a shallow copy, or copy.deepcopy() for nested lists.