Python – Keywords and Identifiers

In this article we are going to discuss about keywords and identifiers in Python.

Keywords are prearranged and predefined words in python. Every keywords are written in lower case except True and False. If we count there are 33 keywords in python. Keywords are case sensitive. We can not create any function or identifiers with matching keyword name. I python these keywords are  made for particular purpose.

All Python Keywords are listed below:

1 and It is a logical operator. If both the operands are true it returns true otherwise false.
2 Or It is also a logical operator. Returns true if anyone operand is true otherwise return false.
3 not This is again a logical operator. Returns True if the operand is false else return false.
4 if  Conditional statement.
5 elif Elif is a condition statement used with if statement the elif statement is executed if the previous conditions were not true
6 else Else is used with if and elif conditional statement the else block is executed if the given condition is not true.
7 for This is created for a loop.
8 while This keyword is used to create a while loop.
9 break This is used to terminate the loop.
10 as This is used to create an alternative.
11 def It helps us to define functions.
12 lambda It used to define the anonymous function.
13 pass This is a null statement that means it will do nothing.
14 return It will return a value and exit the function.
15 True This is a Boolean value.
16 False This is also a Boolean value.
17 try It makes a try-except statement.
18 with The with keyword is used to simplify exception handling.
19 assert This function is used for debugging purposes. Usually used to check the correctness of code
20 class It helps us to define a class.
21 continue It continues to the next iteration of a loop
22 del It deletes a reference to an object.
23 except Used with exceptions, what to do when an exception occurs
24 finally Finally is use with exceptions, a block of code that will be executed no matter if there is an exception or not.
25 from The form is used to import specific parts of any module.
26 global This declares a global variable.
27 import This is used to import a module.
28 in It’s used to check if a value is present in a list, tuple, etc, or not.
29 is This is used to check if the two variables are equal or not.
30 None This is a special constant used to denote a null value or avoid. It’s important to remember, 0, any empty container(e.g empty list) do not compute to None
31 nonlocal It’s declared a non-local variable.
32 raise This raises an exception
33 yield It’s ends a function and returns a generator.

Python Identifiers

Python identifiers are generally used to recognize a variable, function, class etc. There are some rules which we should follow while choosing a name for identifier-

1.Identifier should start with a character or Underscore after that use digit.

2.Characters are A-Z or a-z, an Underscore ( _ ) , and digit (0-9).

  • For example, value_count, dataLoader etc. are some valid identifier names.

3.We should not use special characters ( #, @, $, %, ! ) in identifiers.

4.No limitation on the length of the identifier.

5.Identifiers are case sensitive, i.e., ‘define & ‘Define are two different identifiers in Python.

6.Avoid using two underscore while giving identifiers name  like __len__ or _load__

Conclusion:

In this article we have discussed all about keywords and identifiers in Python in details. Thank You!