Keywords#

Keywords are reserved words that have a specific purpose within the language, and they can’t be used to assignment variable names. Keywords are used to define control structures, such as if, else, for, and while, and others are used for specific purposes, such as def (to define a function) and import (to import modules).

See below the list of Python Keywords

Keywords list

None

except

and

nonlocal

True

pass

is

await

False

finally

as

lambda

import

def

try

assert

from

while

class

del

return

if

not

global

in

elif

with

async

continue

else

or

yield

break

for

raise

Note

  • Keywords are case-sensitive and must be written in lowercase, excepting for None, True, False.

  • Keywords cannot be used as variable names, function names, or any other identifier in your code.

To obtain the list of keywords:

import keyword
print(keyword.kwlist)
['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']