In Python, keywords are reserved words that have a special predefined meaning and cannot be used as identifiers (e.g., variable names, function names). Keywords are the building blocks of Python syntax and structure.

Most keywords are explained on a different page, so the “Context” column will link to the details.

ContextKeywordDescription
DatatypeFalseBoolean value representing False.
DatatypeTrueBoolean value representing True.
DatatypeNoneRepresents the absence of a value or a null value.
OperatorandLogical AND operator. True if all operands are True.
OperatororLogical OR operator. True if at least one operand is True.
OperatornotLogical NOT operator. Negates a boolean value.
OperatorinChecks if an element exists in a sequence or collection. Also used to iterate a variable in a for loop.
VariableisCheck if two objects have the same identity (=location in memory).
VariabledelDelete an object, variable, or items from a collection.
VariableglobalDeclares a variable as global, accessible outside the current scope.
Flow ControlifDefines a conditional statement.
Flow ControlelifConditional branching; short for “else if”.
Flow ControlelseDefines the block of code to execute if the if condition is False. Also has a special use-case in the context of while, for and except.
Flow ControlwhileDefines a loop that continues as long as the condition is True.
Flow ControlforDefines a loop that iterates over a sequence.
Flow ControlbreakTerminates/jumps after the nearest enclosing loop.
Flow ControlcontinueSkips the remaining code in a loop iteration and moves to the next iteration.
FunctiondefDefines a new function or method.
FunctionreturnExits a function and optionally passes back a value.
OOPclassDefines a new function or class.

Questions

  • What is a keyword? Explain in your own words.