Keywords are reserved words in Python that have special meanings and are used to perform specific tasks. Here is a list of all the Python keywords. All the keyword names are linked to a detailed article where you can learn about that particular keyword in detail.
Keyword | Description |
---|---|
and | Logical operator used to combine conditional statements. |
as | Used to create an alias for a module, function, or class. |
assert | Used for debugging to test if a condition is true, if not, it raises an AssertionError with an optional error message. |
async | Used to define a coroutine, which is a special type of function that can be paused and resumed. |
await | Used to wait for a coroutine to complete before moving on to the next line of code. |
break | Used to exit a loop prematurely. |
class | Used to define a class, which is a blueprint for creating objects. |
continue | Used to skip over a specific iteration of a loop and move on to the next one. |
def | Used to define a function. |
del | Used to delete an object or variable. |
elif | Short for “else if”, used in conditional statements to specify a new condition if the previous ones are false. |
else | Used in conditional statements to specify the code to execute if all previous conditions are false. |
except | Used in try/except blocks to catch and handle exceptions. |
False | Boolean value that represents false. |
finally | Used in try/finally blocks to specify code that will always be executed, regardless of whether an exception was raised or not. |
for | Used to create a for loop, which is used to iterate over a sequence (such as a list or string). |
from | Used to import specific attributes or functions from a module. |
global | Used to declare a variable as global, meaning it can be accessed from anywhere in the code. |
if | Used to create a conditional statement, which is used to execute certain code if a certain condition is true. |
import | Used to import a module. |
in | Used to test if a value is a member of a sequence (such as a list or string). |
is | Used to test if two objects are the same object in memory. |
lambda | Used to create an anonymous function, which is a function without a name. |
pass | Used as a placeholder, does nothing and can be used to avoid syntax errors when no code is required. |
None | Represents a null value or no value. |
nonlocal | Used to declare a variable that is not local to the current function, but also not global. It allows you to modify a variable in the outer (but not global) scope from within a nested scope. |
not | Logical operator used to reverse the truth value of a statement. |
or | Logical operator used to combine conditional statements. |
raise | Used to raise an exception (an error that occurs during program execution). |
return | Used to exit a function and return a value. |
True | Boolean value that represents true. |
try | Used to try a block of code and handle any exceptions that occur. |
while | Used to create a while loop, which is used to repeatedly execute code as long as a certain condition is true. |
with | Used to simplify exception handling by ensuring that a resource is released (e.g. a file is closed) no matter how the block of code exits. |
yield | Used to create a generator, which is a special type of iterator that returns a series of values, one at a time, instead of returning them all at once. |
Note that keywords cannot be used as variable names, function names, or any other identifiers, as they are reserved for their specific purposes in Python.