When Python evaluates a name such as int, range, or sum, it searches available namespaces. The built-in namespace is the final fallback: inside a function, Python searches local, enclosing, global, then built-in names; outside a function, it searches globals before built-ins. Once Python finds the name, it stops. section 6.5
Shadowing a built-in
sum = 0 for i in range(5): sum += i print(sum) print(sum([10, 20, 30])) The final call fails because the global integer named sum is found before the built-in sum function. Avoid redefining built-in names; tools such as pylint can flag these collisions. section 6.5
Keep these distinctions in mind:
- Built-ins are not ordinary global variables, but Python makes their names available through the final lookup level. section 6.5
- Common types and functions such as lists, dicts, and int are built into the language and require no import. section 8.0
- The standard library is broader than the built-ins: modules such as os must be loaded with import before use. section 8.0
sum = 0 for i in range(5): sum += i print(sum) print(sum([10, 20, 30])) TypeError: 'int' object is not callable
Trace a built-in name collision from assignment through failed function invocation. section 6.5


