In this Python Keywords and Identifiers tutorial, we will discuss keywords (reserved words in Python) and identifiers (names given to variables, functions, etc.).
Python Keywords
Keywords are the reserved words in Python.
Keywords are case-sensitive.
We cannot use a keyword as a variable name, function name, or any other identifier.
There are 35 keywords in Python 3.8.8. It may vary depending on your version in python
An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one entity from another.
Rules for writing identifiers:
Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _. Names like testClass, xyz_1 are valid examples.
An identifier cannot start with a digit. 1variable is invalid, but variable1 is a valid name.
The above piece of code will return error from python because we are assign value into 1variable. It start with number.
Difference between Keywords and Identifiers:
KEYWORD
IDENTIFIER
Keywords are predefined word that gets reserved for working progs that have special meaning and cannot get used anywhere else.
Identifiers are the values used to define different programming items such as variables, integers, structures, unions and others and mostly have an alphabetic character.
Specify the type/kind of entity.
Identify the name of a particular entity.
It always starts with a lowercase letter.
First character can be a uppercase, lowercase letter or underscore.
A keyword should be in lower case.
An identifier can be in upper case or lower case.
A keyword contains only alphabetical characters.
An identifier can consist of alphabetical characters, digits and underscores.
They help to identify a specific property that exists within a computer language.
They help to locate the name of the entity that gets defined along with a keyword.