Introduction
Every language contains a set of words that, when combined meaningfully, forms meaningful sentences. Similar to them, there are keywords and identifies present in every programming language that constitutes the vocabulary of the programming language.
In this blog, we will learn about keywords and identifiers in Python.
Also see, Convert String to List Python
What are Keywords?
In Python, keywords are predefined and reserved words with specific meanings. Keywords define the syntax of the code. The keyword can't be used as a variable name, function name, or identifier. Except for True and False, all keywords in Python are written in lower case. There are 36 keywords reserved in Python 3.9.
The major keywords present in Python are
Keyword | Description |
False | boolean value |
True | boolean value |
from | import specific parts of a module |
else | It is a conditional statement that gets executed if all the if’s evaluate to false |
elif | It is a conditional statement that represents else if |
continue | It is a control statement that is used to continue to the next iteration of the loop. |
break | It is a control statement. It used to break from a loop |
assert | It is a debugging statement used to check the correctness of the code |
and | It is a logical operator that returns false if any one of the operands is false or else will return false |
not | It is a logical operator that returns false if the operand is true or else returns true |
or | It is a logical operator that will return true if any one of the operands is true or else will return false |
pass | It is a null statement, i.e., it does nothing |
except | Used in exceptions |
for | Used in for loop |
while | used in while loop |
in | used to check if a value is present in a list, tuple, etc. |
is | used to check if the two variables are equal or not |
as | used to create an alias |
lamda | used to create an anonymous function |
global | Used to declare a global variable |
nonlocal | used to declare a non-local variable |
class | used to define a class |
def | used to define a function |
del | used to delete the reference to the object |
yield | used to end a function and return a generator |
return | used to exit a function and return a value |
import | Used to import a module |
try | used to make a try-except statement |
if | Used to make conditional statement |
raise | Used to raise an exception |
None | used to represent a null value |
with | used to simplify exception handling |
finally | used with exceptions to execute a block of code that will be executed no matter if there is an exception or not |
You can also read about the Multilevel Inheritance in Python, Swapcase in Python