0% found this document useful (0 votes)
33 views4 pages

Python Keywords

The document explains Python keywords, which are reserved words that define the structure of Python programs and cannot be used as identifiers. It provides a method to retrieve the list of keywords and categorizes them based on their context, such as control flow and function definitions. Additionally, it contrasts keywords with identifiers and variables, highlighting their fixed nature and specific meanings in the language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views4 pages

Python Keywords

The document explains Python keywords, which are reserved words that define the structure of Python programs and cannot be used as identifiers. It provides a method to retrieve the list of keywords and categorizes them based on their context, such as control flow and function definitions. Additionally, it contrasts keywords with identifiers and variables, highlighting their fixed nature and specific meanings in the language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Keywords

Last Updated : 3 Dec, 2025




Keywords in Python are special reserved words that are


part of the language itself. They define the rules and
structure of Python programs which means you cannot use
them as names for your variables, functions, classes or any
other identifiers.

Getting List of all Python keywords


We can also get all the keyword names using the below
code.
import keywordprint("The list of keywords are :
")print([Link])

Output

The list of keywords are:


['False', 'None', 'True', 'and', 'as', 'assert', 'async',
'await', 'break', 'class', 'continue', 'def', 'del',
'elif', 'else', 'except', 'finally', 'for', 'from', 'global',
'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not',
'or', 'pass', 'raise', 'return', 'try', 'while', 'with',
'yield']

Identify Python Keywords


Ways to identify Python Keywords are:
 With Syntax Highlighting: Most of IDEs provide
syntax-highlight feature. You can see Keywords
appearing in different color or style.
 Look for SyntaxError: This error will encounter if you
have used any keyword incorrectly. Keywords can not be
used as identifiers like variable or a function name.

Keywords as Variable Names


If we attempt to use a keyword as a variable, Python will
raise a SyntaxError. Let's look at an example:

for = 10
print(for)

Output

Hangup (SIGHUP)
File "/home/guest/sandbox/[Link]", line 1
for = 10
^
SyntaxError: invalid syntax

Let's categorize all keywords based on context for a more


clear understanding.

Category Keywords

Value Keywords True, False, None

Operator
and, or, not, is, in
Keywords

Control Flow if, else, elif, for, while, break, continue, pas
Keywords s, try, except, finally, raise, assert

Function and
def, return, lambda, yield, class
Class

Context
with, as
Management

Import and
import, from
Module

Scope and
global, nonlocal
Namespace

Async async, await


Category Keywords

Programming

Keywords vs Identifiers
Keywords Identifiers

Reserved words in Python that Names given to variables,


have a specific meaning. functions, classes, etc.

Cannot be used as variable Can be used as variable


names. names if not a keyword.

Examples: x, number, sum,


Examples: if, else, for, while
result

User-defined, meaningful
Part of the Python syntax.
names in the code.

They cannot be redefined or Can be defined and redefined


changed. by the programmer.

Variables vs Keywords
Variables Keywords

Reserved words with


Used to store data. predefined meanings in
Python.

Can be created, modified, and Cannot be modified or


deleted by the programmer. used as variable names.

Examples: x, age, name Examples: if, while, for

Hold values that are manipulated Used to define the


in the program. structure of Python code.

Variable names must follow Fixed by Python language


Variables Keywords

naming rules but are otherwise


and cannot be altered
flexible.

You might also like