Python Keywords
In Python, keywords are reserved words that have a special meaning in the language. They are used to perform specific operations or to define the structure of the program. There are 35 keywords in Python, and they cannot be used as variable names, function names, or any other identifier names.
Here is a list of some of the most commonly used keywords in Python:
and
: used to combine two or more conditions in a logical expressionas
: used to import a module using an aliasassert
: used to check if a certain condition is true, and raises an exception if it is notasync
: used to define an asynchronous functionawait
: used to wait for an asynchronous function to completebreak
: used to exit a loopclass
: used to define a new classcontinue
: used to skip the current iteration of a loopdef
: used to define a new functiondel
: used to delete an object or an element from a collectionelif
: used as a short form for "else if" in a conditional statementelse
: used as a part of a conditional statementexcept
: used to handle exceptionsFalse
: a boolean literal representing the value Falsefinally
: used to specify a block of code that will be executed regardless of whether an exception is raisedfor
: used to create a for loopfrom
: used to import specific elements from a moduleglobal
: used to specify that a variable is a global variableif
: used as a part of a conditional statementimport
: used to import a modulein
: used to check if an element is present in a sequenceis
: used to check if two variables refer to the same objectlambda
: used to create an anonymous functionNone
: a special constant representing the absence of a valuenonlocal
: used to specify that a variable is nonlocalnot
: used to negate a logical expressionor
: used to combine two or more conditions in a logical expressionpass
: used as a placeholder when a statement is required but no action is to be performedraise
: used to raise an exceptionreturn
: used to exit a function and return a valueTrue
: a boolean literal representing the value Truetry
: used to enclose a block of code that may raise an exceptionwhile
: used to create a while loopwith
: used to create a context manageryield
: used to define a generator function
Note that all keywords except for True, False, and None
are in lowercase and must be written as they are.
It is important to note that keywords cannot be used as variable names, function names or any other identifier.