Python Keywords
Python Keywords
assert
It is used when debugging code. It lets you test if a condition in your code returns True, if
not, the program will raise an Error.
break
It terminates the current loop and resumes execution at the next statement. It can be used
in both while and for loops.
class
A template for creating user-defined objects.
continue
It is used to end the current iteration in a for loop or a while loop and goes to the next
iteration.
def
marks the start of the function header. A function name to uniquely identify the function.
del
It can be used to erase an item at a given index and to remove slices from a list.
elif
It is the same as "else if" in other programming languages.
else
It is used in conditional statements (if statements), and decides what to do if the condition
is False.
except
It is used to catch and handle the exception(s) that are encountered in the try clause.
finally
It is always executed after try and except blocks. It always executes after normal
termination of try block or after try block terminates due to some exception.
global
It allows you to modify the variable outside of the current scope.
if
It is used for decision-making operations. It contains a body of code which runs only when
the condition given in the statement is true.
import
It is used to make code in one module available in another.
lambda
An anonymous inline function consisting of a single expression which is evaluated when
the function is called.
nonlocal
It is used to work with variables inside nested functions, where the variable should not
belong to the inner function.
none
It is used to define a null value, or no value at all. It is not the same as 0, False, or an
empty string.
pass
It is a null statement. The interpreter does not ignore this statement, but nothing happens,
and the statement results into no operation.
raise
It is used to produce an exception to interrupt the code execution.
return
it is used to end the execution of the function call and gives the result to the caller.
try
This block lets you check some code for errors.
while
It is a control flow statement which allows code to be executed repeatedly, depending on
whether a condition is satisfied or not.
yield
It is a keyword that is used like return, but the function will return a generator.