Python Keywords
Python Keywords
Python keywords are reserved words that have predefined meanings. The Python Interpreter uses keywords to understand the program. Python uses several keywords that cannot be used as identifiers. Python does not allow the use of a keyword as a variable name, function name, etc. Keywords in Python language are case-sensitive.
Python Keywords
The keywords may get altered in different versions of Python. We can get the list of keywords in our current version by typing the following in the prompt.
False | class | from | or |
None | continue | global | pass |
True | def | if | raise |
and | del | import | return |
as | elif | in | try |
assert | else | is | while |
async | except | lambda | with |
await | finally | nonlocal | yield |
break | for | not |
We can get the complete list of keywords using the Python interpreter help utility. There are 35 keywords in the Python 3.x release.
Type help() for interactive help at the Python interpreter prompt.
>>> help()
To get a list of available keywords, type keywords
help> keywords
Each keyword in Python language has a specific function and is integral to the structure of a Python program.
Python Keyword | Description |
False | The False keyword represents the boolean false value. |
None | The None keyword represents the absence of a value or a null value. |
True | The True value represents the boolean true value. |
and | The and is a logical operator used to combine conditional expressions. |
as | The as keyword is used to create an alias while importing a Python module. |
assert | The assert keyword is used for debugging purposes. |
async | The async keyword is used to declare an asynchronous function. |
await | The await keyword is used to wait for the completion of an asynchronous function. |
break | The break keyword is used to break out of a loop. |
class | The class keyword is used to define a new class in Python. |
continue | The continue skips the rest of the code inside a loop for the current iteration only. |
def | The def keyword is used to define a function. |
del | del keyword is used to delete a reference to an object. |
elif | The elif is used in conditional statements, same as else if. |
else | else is used in conditional statements. |
except | except keyword is used with exceptions, what to do when an exception occurs. |
finally | The finally keyword is used with exceptions, a block of code that will be executed no matter if there is an exception or not. |
for | The for keyword is used for looping, typically used with the in keyword. |
from | from keyword is used to import specific parts of a module. |
global | The global is used to declare a global variable. |
if | if is used for conditional branching. |
import | import keyword is used to import a module. |
in | in checks if a value is present in a Python data structure like list, tuple, etc. |
is | is tests for object identity. |
lambda | The lambda keyword is used to create an anonymous function. |
nonlocal | nonlocal declares a non-local variable. |
not | not is a logical operator used to invert the truth value. |
or | or is a logical operator used to combine conditional expressions. |
pass | The pass is a placeholder for a null statement. |
raise | raise keyword is used to raise an exception. |
return | return is used to exit a function and return a value. |
try | try is used to specify exception handlers and/or cleanup code for a group of statements. |
while | The while keyword is used for looping. |
with | with keyword is used to wrap the execution of a block of code. |
yield | The yield keyword ends a function and returns a generator. |
The keywords have special meanings and are part of the syntax of the Python language. These keywords provide the basic structure and control flow mechanisms in Python programming.
—
Python Tutorials
Python Tutorial on this website can be found at:
https://www.testingdocs.com/python-tutorials/
More information on Python is available at the official website: