Python Keywords and Identifiers

Python Keywords

In Any programming language that you learn there are some predefined words which has some internal implementation. And they have some specific function.

Likewise, in python we have 35 reserved words as per Python3.9.0 and may increase with course of time.

Points to remember about Python Keywords

  • We can not use Python keywords for defining variables names, functions and other identifiers.
  • In Python, Keywords are case sensitive.
  • All Keywords except True, False and None starts with lower case letters.

If you look at all the keywords and try to remember everything on day one, that will be overwhelming, You will learn with course of time.

Python Identifiers

Identifiers are the name given to the entities like classes, variables and functions etc. It helps to differentiate one entity from other.

There are certain rules we have to follow while defining identifiers.

Rules for writing identifiers

Rule 1. 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 myClass, var_1 and print_this_to_screen, all are valid example.

Rule 2. An identifier cannot start with a digit. 1variable is invalid, but variable1 is a valid name.

Rule 3. Keywords cannot be used as identifiers. ex: global = 1;

Output
File "<interactive input>", line 1 
  global = 1 
         ^ 
SyntaxError: invalid syntax

Rule 4. We cannot use special symbols like !@#$% etc. in our identifier. ex: a@ = 0

Output
File "<interactive input>", line 1 
  a@ = 0 
   ^ 
SyntaxError: invalid syntax

Rule 5: Identifiers can be of any length

Things to take care

Python is a case sensitive language that means variable and Variable are not same.

Always use the meaningful identifier name which makes some sense. Ex: c=10 is perfectly valid but if you define count = 10, this will make more sense.

Leave a Reply