Keywords and Identifiers in python.

Keywords are reserved words with a special meaning. Every programming language has some reserved words known as a keyword. Identifiers are the name that are used to identify an array, variable, function, class ETC.

What are the Keywords and Identifiers in Python

Python contains around 33 keywords. Some of them are common as other programming languages like if, else, True and False, etc. Let’s understand Keywords and Identifiers in python in detail.

Keywords in Python

A Python keyword is a reserved word which you can’t use as a name of your variable, class, function and so on.

They are used defining the syntax  and structure of the Python language. For instance, Python keyword “if” is used for condition statements, hence you cannot use “if” as a variable in your program.

In Python, keywords are case sensitive.

There are more than 33 keywords in Python 3.7. This number can fluctuate marginally through the span of time.

All the keywords aside from True, False, and None are in lowercase and they should be composed as they may be. The rundown of the considerable number of keywords is given underneath.

Let us consider an example using Python keyword:

In the above example, it will print whether you are eligible to vote or not depending on your age. Python understands the if-else because it is a fixed keyword and syntax then the further processing is done.

Take a note at the indentation as in Python without proper indentation you wont get the output.

Identifiers in Python

Variable name is known as identifiers in Python. Hence,Identifiers are containers for storing values.

An identifier is a name given to entities like class, functions, variables, and so forth. It assists with separating one element from another. An identifier begins with a letter A to Z or a to z or an underscore (_) trailed by at least zero letters, underscores, and digits (0 to 9).

Python doesn’t permit accentuation characters, for example, @, $, and % inside identifiers. Python is a case sensitive programming language. In this manner, Table and table are two unique identifiers in Python.

Naming conventions for identifiers:

  1. Class names start with a capitalized letter. Every single other identifier starts with a lowercase letter or an underscore. Example: _avg, new, and so on.
  2. The name of a variable cannot start with a number. Example: 2avg, 24age, and so on.
  3. Identifiers cannot have special characters, they can only have alphanumeric characters or underscore(_). Example: avg1 = 30, new_avg = 55, and so on.
  4. As discussed earlier, Python is a case sensitive programming language. Hence Total and total are two different variables.
  5. Beginning an identifier with a solitary driving underscore shows that the identifier is private. Example:  _num= 70

Here is a Python program of legal variable names for your reference:

Illegal variable names are:

Difference between Keywords and Identifiers in Python.