Python Language Keywords

Python try Keyword

The try keyword is used in conjunction with the except keyword and often the finally keyword to wrap blocks of code that may throw an error.

Python break Keyword

Used to break out of a loop. A break statement terminates the nearest enclosing for or while loop.

Python class Keyword

This keyword defines a class which is a container for attributes (variables and functions). A class can have an initializer as well.

Python continue Keyword

To continue to the next iteration of a loop. Placing this keyword in a loop skips everything after the continue statement in the nearest for or while loop.

Python def Keyword

To define a function. def Indicates that what follows is a function definition. A function is a block of statements that:

Python del Keyword

To delete an object. The del keyword deletes an object, usually something in a list.

Python elif Keyword

Used in conditional statements, same as else if. If the previous condition was not true, and the next condition is true, execute the code in the elif block. This is shorthand for else if.

Python else Keyword

Used in conditional statements. When all other conditions are false, the code block defined by the else keyword is executed.

Python except Keyword

Used with exceptions, what to do when an error occurs. The except keyword is used in conjunction with the try keyword and often the finally keyword. It lets you define a code block that handles exceptions.

Python False Keyword

A boolean value indicating "not true", which can be the result of comparison operations or can simply be assigned as a value.

Python finally Keyword

Used with try/catch blocks and marks a block of code that will be executed no matter if an exception was thrown or not. The finally keyword is used in conjunction with the try keyword and except keywords. Regardless of the exception, the code in the finally block will always run.

Python for-else Keywords

The code in the else block will execute if the for loop did not encounter a break.

Python assert Keyword

For debugging. This asserts that something is True.

Python from Keyword

Used importing from a module. Using from [module name] import [object name] will import only one specific object in the Python module being imported. Importing modules makes the objects in those modules accessible to the module doing the import.

Python if Keyword

The start of a conditional statement. The code block defined by an if statement executes only if the condition is true.

Python import Keyword

Modules (usually code in sub-directories) are a way of organizing your code. The import keyword is used to tell Python "hey, I want to use some code in another this other module."  This is particularly useful when the module has many Python code files. Using the import keyword, you can then access the functions and classes defined in the imported module.

Python import as Keyword

Using import [module name] as [alias] will import the Python module and alias the module name.

Python in Keyword

Used to check if a value is present in a list, array etc. When used with an if statement or in an expression, in returns True or False depending on whether a value in a collection.

Python is Keyword

The is keyword is used to determine if two variables reference the same object.

Python for Keyword

Used to create a for loop. For loops are used to iterate over a collection or range.

Python lambda Keyword

Used to create an anonymous (lambda) function

Python None Keyword

None is used to indicate "no value."  There are times when you may want to explicitly say "there is no value".

Python nonlocal Keyword

The nonlocal keyword is used to work with variables inside nested functions, where the variable should not belong to the inner function.

Python not Keyword

A logical operator that returns True if the statement is False, returns False if the statement is True.

Python or Keyword

A logical operator that returns True if either side of the "or" are True.

Python global Keyword

Allows the conversion of a global read-only variable into a writeable variable.

Python pass Keyword

A null statement, meaning a statement that will do nothing,

Python as Keyword

The "as" keyword is used to create an alias for an imported module.

Python and Keyword

A logical operator the returns true if both sides of the "and" are true.

Python raise Keyword

Raises an exception when a condition is true. The exception can then be caught by other code with the except keyword.

Python True Keyword

True is a boolean value that indicates that that a value or the result of a comparison in true.


Used to exit a function and return a value

Python while Keyword

Creates a while loop. A while continues looping over the enclosed code block until the while condition is no longer True.

Python yield Keyword

Used to return a generator from a function.