why is functions like len
and max
not a reserved keyword in python. Following are the only reserved words http://docs.python.org/2/reference/lexical_analysis.html#keywords
6
It doesn’t make sense to privilege the built in functions like len, str, and so on, because that would require a core language change. To add len
and so on to the core language would require changes to the parser to recognize and reject changes to them. And adding parser changes can be quite risky for a very small benefit, and it could also impact performance.
When on the other hand, it keeps the language clean and simple, and enables useful edge cases, for example redefinitions of len, etc. While this might scare you, I guarantee you it was useful to someone somewhere.
If you’re paranoid that someone overwrote len, you can always do the following:
from __builtins__ import len as SUPERSECURELEN
You cannot modify the builtins module. So its safe.
1