The built-in namespace supplies common names such as int and sum when Python resolves an identifier. Lookup follows LEGB: local, enclosing, global, then built-ins; Python stops at the first match. section 7.5
Avoid common lookup failures:
- Do not redefine built-in names such as sum; a global variable shadows the built-in and can make sum(...) fail with TypeError. section 7.5
- Remember that indentation alone does not create a new scope; function definitions create local scope. section 7.5
- Use pylint or ruff to detect accidental collisions with built-in names. section 7.5
sum = 0
for i in range(5):
sum += i
print(sum)
print(sum([10, 20, 30]))
TypeError: 'int' object is not callable
Compare a shadowing assignment with a call to the original built-in sum. section 7.5


