Keywords in Python

Keywords in Python

Keywords in Python are reserved words which cannot be used as identifiers where identifier is a name of a function, a variable, a class or any object. A number of keywords are available for use which have specific purpose and are listed below in the table.

 

Keywords in Python Description
and This keyword works on two operands and returns True only if both of them are True, otherwise False.
as This keyword is used to create an alias which is basically another name for something.
assert This keyword is used for debugging.
break This keyword is used to stop the loop from executing and the control falls to the statement immediately after it.
class This keyword is used to define a class.
continue This keyword is used to skip the current iteration of the loop and moves to the next iteration.
def This keyword is used to define a function.
del This keyword is used to delete an object.
elif This keyword is used in conditional statements and is a variant of if statement. It is used so that more than one condition can be specified.
else This keyword is used in conditional statements and is a variant of if statement. It is used to specify the last block that is executed if none of the conditions specified by if and elif is True.
except This keyword is used with exceptions and tells what to do when an exception occurs.
False This is one of the boolean values and is returned as a result of comparison operations.
finally This keyword is used with exceptions and represent a block of code that will execute no matter if an exception occurs or not.
for This keyword is used to create a for loop.
from This keyword is used to import certain and specific parts of a module that is being imported in the current script.
global This keyword is used to declare a global variable.
if This keyword is used in conditional statements.
import This keyword is used to import a module is the current script.
in  This keyword is a membership operator which validates membership of an object in the sequence like tuple, list, string, etc.
is This keyword is used to test if two variables are equal.
lambda This is used to create an anonymous function.
None This keyword represents null value.
nonlocal This keyword is used to declare a non-local variable.
not This keyword represent a logical operator returns True if its operand is False and False if its operand is True.
not in This keyword is a membership operator which validates no-membership of an object in the sequence like tuple, list, string, etc.
or This keyword works on two operands and returns True if any of them is True, otherwise False.
pass This keyword represents statement that does nothing. It is used when the code requires a statement but does not want it to do anything.
raise This keyword is used to raise an exception
return This keyword is used to exit a function and to return a value.
True This is one of the boolean values and is returned as a result of comparison operations.
try This keyword is used to make a try…except statement and represent a block of code that may result in an exception
while This keyword is used to create a while loop.
with This keyword is used to simplify exception handling.
yield This keyword is used to end a function and returns a generator.
Share this post

One thought on “Keywords in Python

Leave a Reply

Your email address will not be published.