1. Ultimate Reference to Python Keywords

Python language provides a list of reserved words or keywords that we mostly use while writing our programs. These are the words that we cannot modify or change for any purpose and the interpreter uses these words to understand the program. Further, these built-in keywords build the structure of the program and we cannot utilize them for naming variables, classes, functions, etc. In this tutorial, we will provide you with all the keywords and soft keywords in Python programming, which will be an ultimate and up-to-date guide or reference for the developers.

Tutorial Contents:

  1. Ultimate Reference to Keywords
  2. All Keywords
  3. Dynamically Get All Keywords
  4. All Soft Keywords
  5. Dynamically Get All Soft-Keywords
  6. Reference Links

2. Search Ultimate Reference For Python Keywords

The below table comprises of complete list of keywords in an alphabetical manner. Use the search field to find the keyword from the list. Further, this is an ultimate and up-to-date list of all keywords or reserved words in Python programming.

2.1. Alphabetical Reference

Keyword Description
and A logical operator
as Creates an alias
assert For debugging
async Define asynchronous functions
await Suspend or pause the execution of asynchronous functions to perform the awaited operation
break To break out of a loop
class To define a class
continue Unlike break, continues to the next iteration in the loop
def Define a function with this keyword
del Delete an object with this keyword
elif Short for else if, used in conditional statements
else Used in conditional statements
except Used with exceptions, what to do when an exception occurs
False Boolean value, used for comparison operations
finally Used with exceptions, executes a block even with exception
for To create a for loop
from To import specific parts of a module
global Declares a global variable
if Makes a conditional statement
import Imports a module
in It checks if a value is present in a list, tuple, etc.
is To test if two variables are equal
lambda Creates an anonymous function
None Represents a null value
nonlocal Declares a non-local variable
not A logical operator
or A logical operator
pass A null statement, a statement that will do nothing
raise Raises an exception
return To exit a function and return a value
True Boolean value, used for comparison operations
try Used with except statement
while Creates a while loop
with Used to simplify exception handling
yield Returns a list of values from a generator

3. Dynamically Get All Python Keywords

In Python programming, we can dynamically retrieve all the keywords using some script. Below are the two methods to acquire all the keywords in the Python programming package.

Get All Python Keywords

Method 1
# Get a complete keyword list
import keyword

python_keywords = keyword.kwlist
print(python_keywords)
Method 2
# Get a complete keyword list

help() # Run this command
help> keywords # Input "keywords" upon prompt

4. Python Soft Keywords List

Some keywords or identifiers in Python are reserved in specific contexts, which are known as soft keywords and are listed below.

Keyword Description
_ A placeholder variable in Python
match A pattern matching expression that allows handling of complex conditional statements
case Used within the match to define specific patterns
type Used for type hinting to get data types of function parameters

5. Dynamically Get All Python Soft Keywords

Get All Soft Keywords

# Get Soft keywords list
import keyword

soft_keywords = keyword.softkwlist
print("Soft Keywords:", soft_keywords)

6. Reference Links

For this ultimate and up-to-date reference tutorial of Python keywords and soft keywords, which contains all keywords, we consulted and compiled resources from the below websites.

Give Us Your Feedback
OR
If You Need Any Help!
Contact Us