Keywords in Python
Keyword Description
and logical operator AND
or Logical operator OR
not Logical operator NOT
True Boolean Value
False Boolean value
class Defining a class
def Defining a function
lambda Defining short functions
return Return a value from function
yield Create generator
if If conditional statement
elif Shortcut for else if
else else clause of if conditional statement
continue To continue to the next iteration
break Breaking out of loop
pass Null statement instructing to do noting
try Try something to handle exception if occurs
except To handle exception
assert For checking something how it supposed to be (debugging purposes e.g. –
checking shape of an matrix or vector before calculating eigen vector)
raise Raising an exception
for Creating definite loop
while Creating indefinite loops
global Declaring global variable
nonlocal Declaring a non local variable
with Opening file
in Checking a value in data structures
is Checking if two variables are equal
from Import certain function from another file
import Importing a module
finally Used with exceptions, a block of code that will be executed no matter if
there is an exception or not
None For representing null value
del Deleting an object
as Creating an alias

Keywords in python

  • 1.
    Keywords in Python KeywordDescription and logical operator AND or Logical operator OR not Logical operator NOT True Boolean Value False Boolean value class Defining a class def Defining a function lambda Defining short functions return Return a value from function yield Create generator if If conditional statement elif Shortcut for else if else else clause of if conditional statement continue To continue to the next iteration break Breaking out of loop pass Null statement instructing to do noting try Try something to handle exception if occurs except To handle exception assert For checking something how it supposed to be (debugging purposes e.g. – checking shape of an matrix or vector before calculating eigen vector) raise Raising an exception for Creating definite loop while Creating indefinite loops
  • 2.
    global Declaring globalvariable nonlocal Declaring a non local variable with Opening file in Checking a value in data structures is Checking if two variables are equal from Import certain function from another file import Importing a module finally Used with exceptions, a block of code that will be executed no matter if there is an exception or not None For representing null value del Deleting an object as Creating an alias