What are keywords?
Keywords in Python are reservered words that cannot be used as ordinary
identifiers. They must be spelled exacty as they are written.
List of keywords
The following is a list of keywords for the Python programming language.
and del from not while
as elif global or with
assert else if pass yield
break except import print
class exec in raise
continue finally is return
def for lambda try
This prints the keyword list of Python.
>>> import keyword
>>> print keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else',
'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is',
'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with',
print to console
controlling the flow of the program
iterate over items of a collection in order that they appear
interrupt the (loop) cycle, if needed
used to interrupt the current cycle, without jumping out of the whole cycle.
New cycle will begin.
used to determine, which statements are going to be executed.
stands for else if.If the first test evaluates to False,
then it continues with the next one
is optional. The statement after the else keyword is executed,
unless the condition is True
tests for object identity
negates a boolean value
all conditions in a boolean expression must be met
at least one condition must be met.
import other modules into a Python script
if we want to give a module a different alias
for importing a specific variable, class or a function from a module
used to create a new user defined function
exits the function and returns a value
creates a new anonymous function
access variables defined outside functions
specifies exception handlers
catches the exception and executes codes
is always executed in the end. Used to clean up resources.
create a user defined exception
used for debugging purposes
used to create new user defined objects
executes Python code dynamically
is used with generators
For a more detailed explanation and examples of keywords, please see:
Read more about: