In other words, why does Python allow variable names which are identical to built-in type names such as int, float, list, etc? (C++ built-in type names are all reserved, in comparison). Consider the example
# int = 1
i = 2
if type(i) == int:
print 'Is int'
else:
print 'Not int'
The output is "Is int". However, if I uncomment the first line, the output will be "Not int". Obviously my "int" has overridden the built-in type int. That is, in my opinion, potentially dangerous.
From a blog post on the History of Python by the Python language designer:
Built-in names are just system provided objects, variables with pre-defined values. You are free to re-define these on a module-by-module or function-by-function basis. Making this (rather large list) of names reserved keywords would go against the above stated philosophy.
Making built-in types and functions reserved keywords would also make it very hard to introduce any new names to that list. Adding to the reserved keyword list has severe consequences for forward compatibility. Imagine adding a
color
type to the language; every piece of code ever written to handle images would need to be re-written to avoid using that new keyword.Quoting from that same post again: