Python Keywords Guide: What Every Developer Must Know (2026)
Jan 21, 2026 5 Min Read 195 Views
(Last Updated)
Keywords in Python form the foundation of the language’s syntax and structure. These reserved words have predefined meanings and specific purposes within the Python interpreter, making them essential building blocks for writing functional code.
Python 3.11 has exactly 35 keywords that cannot be used as variable names, function names, or any other identifiers. These words, written mostly in lowercase (except True and False), serve as the backbone of Python’s grammar.
This guide explains what keywords in Python are, why they matter for your programming journey, and how to use them correctly. You’ll learn the difference between keywords and identifiers, discover various types of keywords, and understand why Python reserves these special words. Additionally, we’ll explore how the list of Python keywords has evolved over time, with changes between different Python versions. Let’s begin!
Quick Answer:
Python keywords are reserved words with predefined meanings that define the language’s syntax and cannot be used as variable or function names.
Table of contents
- What Are Python Keywords and Why They Matter
- Difference between keywords and identifiers
- Why keywords are reserved in Python
- Types of Python Keywords Explained
- 1) Value keywords: True, False, None
- 2) Operator keywords: and, or, not, is, in
- 3) Control flow keywords: if, elif, else, pass
- 4) Loop keywords: for, while, break, continue
- 5) Function and class keywords: def, return, class, lambda
- 6) Exception handling keywords: try, except, raise, finally, assert
- Advanced Keyword Concepts in Python
- 1) Soft keywords and their purpose
- 2) match, case, and _ in pattern matching
- 3) type as a soft keyword in Python 3.12
- 4) Deprecated keywords: print and exec
- Working with Keywords Programmatically
- 1) Using the keyword module
- 2) keyword.kwlist and keyword.softkwlist
- 3) Checking if a string is a keyword
- 4) Using help() to explore keyword usage
- Concluding Thoughts…
- FAQs
- Q1. What are Python keywords and why are they important?
- Q2. How many keywords are there in Python 3.11 and 3.12?
- Q3. Can I use Python keywords as variable names?
- Q4. What is the difference between standard keywords and soft keywords in Python?
- Q5. How can I programmatically check if a word is a Python keyword?
What Are Python Keywords and Why They Matter
Python keywords are special reserved words with predefined meanings that cannot be used as identifiers elsewhere in your code. These words establish the fundamental rules of the language. Currently, Python has thirty-five keywords and four soft keywords. One important aspect of keywords is that they’re always available in your Python environment—you never need to import them.
Keywords are case-sensitive, with most written entirely in lowercase except for True, False, and None. You’ll recognize terms like if, else, for, while, and import among the complete list of Python keywords.
Difference between keywords and identifiers
Understanding the distinction between keywords and identifiers is crucial for Python programming:
- Keywords: Reserved words with fixed meanings and purposes in Python
- Identifiers: Names that you assign to variables, functions, classes, or other objects
Essentially, whenever you name something in your code, you’re creating an identifier. However, identifiers cannot be keywords. For instance, you can name a variable counter but not if or while.
Identifiers follow specific rules—they must begin with a letter or underscore, can contain letters, numbers, and underscores, and cannot include spaces or special characters. Moreover, unlike keywords, identifiers can be modified and redefined throughout your code.
Why keywords are reserved in Python
- Python reserves keywords for several important reasons. First, keywords define the syntax and structure of the language itself. They provide the building blocks necessary for constructing valid Python statements.
- Indeed, attempting to assign a value to a keyword will result in a SyntaxError. This restriction differs from Python’s built-in functions and types, which—although not recommended—can technically be reassigned without causing immediate errors.
- The list of Python keywords has evolved. For example, both print and exec were keywords in Python 2.7 but became built-in functions in Python 3. Conversely, await and async weren’t added until Python 3.7.
- By protecting these crucial terms, Python ensures code consistency, prevents ambiguity, and maintains the language’s structural integrity across all Python programs.
Types of Python Keywords Explained
Python features several categories of keywords that serve distinct purposes throughout your code. Let’s explore these different types and understand their specific functions.
1) Value keywords: True, False, None
Value keywords are the only capitalized keywords in Python. True and False represent Boolean values, functioning as constants that can’t be reassigned. None signifies the absence of a value, frequently returning from functions without explicit return statements.
2) Operator keywords: and, or, not, is, in
Operator keywords handle logical operations and comparisons. The and keyword returns true when both operands are truthy. Or returns true if at least one operand is truthy. Not simply return the opposite Boolean value. It performs identity checks to determine if two objects are exactly the same in memory. It verifies if an element exists within a container.
3) Control flow keywords: if, elif, else, pass
Control flow keywords direct program execution. If, elif, and else create conditional branches in your code. The pass keyword acts as a placeholder that does not act, allowing you to maintain code structure when implementation is pending.
4) Loop keywords: for, while, break, continue
Loop keywords manage iterations. For loops, iterate over sequences using a combination of for and in. While loops execute repeatedly as long as a condition remains true. Break terminates a loop prematurely, regardless of the remaining iterations. Continue skips the current iteration and proceeds to the next one.
5) Function and class keywords: def, return, class, lambda
Structure keywords establish code organization. Def defines functions, return specifies values to output from functions, and class creates object blueprints. Lambda creates anonymous single-expression functions that automatically return results.
6) Exception handling keywords: try, except, raise, finally, assert
Exception keywords manage errors in Python. Try blocks contain code that might raise exceptions, while except handles these exceptions. Raise manually triggers exceptions, finally specifies code that always executes regardless of exceptions, and asserts verifies conditions during development.
Advanced Keyword Concepts in Python
Beyond standard keywords, Python has evolved to include more flexible language elements that enhance code expressiveness. These advanced concepts demonstrate how the language has matured to balance backward compatibility with new features.
1) Soft keywords and their purpose
- Soft keywords function as keywords only in specific contexts, yet can be used as variable names elsewhere in your code. This design allows Python to introduce new syntax without breaking existing codebases. The introduction of the PEG parser in Python 3.9 made soft keywords possible, creating more flexibility in language design.
- Unlike regular keywords that always trigger a SyntaxError when used as identifiers, soft keywords behave differently based on context. You can verify if a string is a soft keyword using keyword.issoftkeyword() from the keyword module.
2) match, case, and _ in pattern matching
- The structural pattern matching feature introduced match and case as soft keywords. These words only operate as keywords within a match…case block. This design choice was intentional since programmers frequently use match for regex operations and other variable names.
- In pattern matching, _ serves as a wildcard that matches anything without binding names. This allows you to use it multiple times in the same case statement when dealing with values you don’t need to reference.
3) type as a soft keyword in Python 3.12
With Python 3.12, type joined the list of soft keywords. It was introduced alongside type statements while maintaining its functionality as a built-in function. This addition further demonstrates Python’s approach to language evolution without breaking compatibility.
4) Deprecated keywords: print and exec
Both print and exec were keywords in Python 2.7 but became built-in functions in Python 3. Despite no longer being keywords, using them as variable names remains problematic, as it overrides their function capabilities. Assigning values to them can lead to errors like TypeError when attempting to use their original functionality later.
To keep things interesting, here are a couple of lesser-known facts about Python keywords that many developers overlook:
Keywords Are Version-Specific: The exact list of Python keywords depends on the Python version you’re using. For example, async and await were introduced as keywords only in Python 3.7, while print stopped being a keyword after Python 2.7.
Soft Keywords Are a Modern Addition: Python didn’t always have soft keywords. They were introduced with the new PEG parser in Python 3.9, allowing Python to evolve its syntax without breaking existing code.
These facts show how Python carefully balances language stability with continuous improvement.
Working with Keywords Programmatically
Python’s standard library provides tools for working with keywords programmatically in your code. These built-in capabilities make it easy to identify and validate keywords without manual checking.
1) Using the keyword module
The keyword module in Python gives you programmatic access to language keywords. To use it, simply import the module at the beginning of your script. This module offers functions to test if a string is a keyword and provides sequences containing all defined keywords in the interpreter.
2) keyword.kwlist and keyword.softkwlist
Access all Python keywords through two key attributes:
- keyword.kwlist – Contains all standard keywords in Python
- keyword.softkwlist – Lists all soft keywords (added in Python 3.9)
These lists reflect the keywords in your specific Python version. For instance, await and async weren’t added until Python 3.7, whereas print and exec were keywords in Python 2.7 but became built-in functions in Python 3.
3) Checking if a string is a keyword
To verify if a string is a Python keyword:
import keyword
print(keyword.iskeyword(“if”)) # Returns True
print(keyword.iskeyword(“hello”)) # Returns False
Similarly, check for soft keywords using keyword.issoftkeyword().
4) Using help() to explore keyword usage
The built-in help() function provides information about Python objects, including keywords. By typing help(“if”) in an interactive session, you’ll receive documentation about the keyword’s purpose and syntax, making it valuable for learning how keywords function within Python’s structure.
Master Python the right way with HCL GUVI’s Python Course, where complex concepts like decorators are broken down through real-world examples and hands-on practice. Perfect for beginners and intermediate learners, it helps you write cleaner, reusable, and production-ready Python code with confidence.
Concluding Thoughts…
Understanding Python keywords gives you a solid foundation for effective programming. Throughout this guide, you’ve learned that Python 3.11 features exactly 35 keywords that serve as the building blocks of the language’s syntax. Additionally, Python has evolved to include soft keywords like match, case, _, and the newly added type in Python 3.12.
Keywords differ fundamentally from identifiers because they cannot be used as variable names or function names. This restriction helps maintain Python’s structural integrity across all programs.
As you continue your Python journey, recognizing these keywords will become second nature. The next time you write Python code, pay attention to how these reserved words shape your programming logic and structure. After all, mastering Python keywords is not just about avoiding syntax errors – it’s about speaking the language’s grammar fluently and writing cleaner, more effective code.
FAQs
Q1. What are Python keywords and why are they important?
Python keywords are reserved words with predefined meanings that form the foundation of the language’s syntax. They are important because they help construct statements, control program flow, and maintain the structural integrity of Python code.
Q2. How many keywords are there in Python 3.11 and 3.12?
Python 3.11 has 35 standard keywords. Python 3.12 introduces ‘type’ as a new soft keyword, bringing the total to 35 standard keywords and 4 soft keywords (match, case, _, and type).
Q3. Can I use Python keywords as variable names?
No, you cannot use Python keywords as variable names, function names, or any other identifiers. Doing so will result in a SyntaxError. This restriction helps maintain code consistency and prevents ambiguity in Python programs.
Q4. What is the difference between standard keywords and soft keywords in Python?
Standard keywords are always reserved and cannot be used as identifiers anywhere in your code. Soft keywords, on the other hand, function as keywords only in specific contexts but can be used as variable names elsewhere, providing more flexibility in language design.
Q5. How can I programmatically check if a word is a Python keyword?
You can use the keyword module to check if a word is a Python keyword. Import the module and use the keyword.iskeyword() function for standard keywords or keyword.issoftkeyword() for soft keywords. For example, keyword.iskeyword(“if”) will return True.



Did you enjoy this article?