Python difference between keywords and built-in names
Here we will see some differences between Python keywords and built-in names. If you are acquainted with both the terms you may regard them as terms referring to the similar entity. But it is not.
If you analyze them closely you will find some differences between them. Before we see their difference let us see their definition.
Keywords: They are names reserve for specific purpose. Each keyword stands for one specific meaning and it cannot be altered in any way. For instance, some of the keywords like False, await, else, import, pass, etc. each have one specific meaning in all of Python. Try altering them and you know the consequences.
Built-in names: Built-in names are those names that come with Python inbuilt and they are part of Python at all times. Since keywords are also built into Python they are also part of built-in names. However, there are some built-in names that carry specific meaning but they are not reserved like the keywords. Their meaning can be changed. Some of these built-in names are NotImplemented, ZeroDivisionError, NameError, etc.
Using built-in names as object name
The keywords are reserved, trying to change their meaning is futile. To check the legitimacy of the keywords let us try using some of them as object names in a program. Look at the code below.
>>> False=90 File "<stdin>", line 1 SyntaxError: can't assign to keyword >>> if='String' File "<stdin>", line 1 if='String' ^ SyntaxError: invalid syntax >>> break={23, 78 , 980} File "<stdin>", line 1 break={23, 78 , 980} ^ SyntaxError: invalid syntax
We tried to assign integer, string and set value to False, if and break, obviously Python returned error messages as shown above.
Now let us try to use some of the built-in names that are not keywords as objects name.
>>> NotImplemented=980 >>> NameError='String ' >>> ZeroDivisionError=[23 ,78 ,90 , 'C++ still rocks'] >>> NotImplemented 980 >>> ZeroDivisionError [23, 78, 90, 'C++ still rocks'] >>> NameError 'String ' >>> ZeroDivisionError [23, 78, 90, 'C++ still rocks']
There seems to be no objection from Python in this case.
A little clarification
You may be wondering where does identifier fit into, is it part of the built-in names, what is it relation to the built-in names and keywords?
When we say identifier, it is the collection of all the names in Python including the names in your programs, libraries, etc. So identifer is the superset of keywords and built-in names and all other names.
Here is the simplest note to describe all the three of them.
All keywords are part of built-in names, but all built-in names are not keywords. Among identifier the reserved names are the keywords, the remaining identifier names are the built-in names or just some other names.
Note, there are some reserved identifiers, check the link given below.
Link : Some info on identifier and keywords