Python Keywords/ reserved words
1. In Python, there are 33 keywords compared other languages like Java required 56 keywords. The keywords are designated with a special meaning to each. Meanings of all keywords are fixed and, it cannot be modified or removed. All the keywords need to be used as they have defined (Lower case or Upper case). Keywords are also called the reserved words in the Python programming language. The reserved words in Python are listed in the following table with their meaning.
S.No. |
Keyword |
Description |
1 |
False |
Boolean type of value False |
2 |
True |
Boolean type of value True |
3 |
None |
A NULL value is represented |
4 |
and |
Logical AND operator |
5 |
not |
Logical NOT operator |
6 |
or |
Logical OR operator |
7 |
for |
A for loop is created |
8 |
while |
A while loop is Created |
9 |
if |
It’s a conditional statement |
10 |
else |
It’s used in conditional statements like if |
11 |
elif |
Looks like a else if , It’s also used in conditional statements. |
12 |
break |
Out of a loop |
13 |
continue |
It’s Used to move to the next iteration of a loop |
14 |
pass |
A null statement, nothing it do’s |
15 |
class |
A class is created |
16 |
def |
A function is created |
17 |
del |
An object is deleted |
18 |
as |
Used to create an alias |
19 |
from |
To import specific parts of a module |
20 |
in |
Weather a value is present in a list, tuple, etc ., are checked |
21 |
is |
Checks if two variables are equal |
22 |
import |
To import a module |
23 |
assert |
It’s used for debugging |
24 |
lambda |
An anonymous function is created by lambda . |
25 |
nonlocal |
A non-local variable used to declare |
26 |
global |
A global variable is used to declare |
27 |
except |
Used with exceptions, what to do when an exception occurs |
28 |
finally |
Used with exceptions, what to do when none of the specified exceptions solved |
29 |
raise |
Used to raise an exception |
30 |
return |
Used to exit a function and return a value |
31 |
try |
Used to make a try...except statement in exception handling |
32 |
with |
Used to simplify exception handling |
33 |
yield |
Used to end a function, returns a generator |
1. All reserved words in Python are composed exclusively of alphabetic characters.
2. All contain solely lower case alphabetic symbols, with the exception of the following three reserved words that are True, False, None.
If we want view the reserved words in python we need type
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else','except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']