Source:
int = 33
float = 0.0
while = 33
Output:
while = 33
^
SyntaxError: invalid syntax
Why does assignment to int and float are not generating error in python whereas assignment to while generates error?
CodePudding user response:
while
is a keyword. Keywords are essential parts of the language that cannot be used as variable names.
int
and float
are built-in types. That means they already essentially are variable names, but they are automatically assigned to standard parts of the library for you to use. However, that does not prevent you setting them to something else.
NB Though you can do it, it is generally inadvisable to set the names of built-ins to something else, because it leads to unclear code and confusing bugs.