Keywords are unique sets of predefined words that convey a special meaning to the compiler/interpreter. Each keyword has a special meaning and special operation. Every programming language has keywords. Here we will know about Python Keywords.

A keyword name can’t be used as a variable name or function name.

How to identify keywords ?

Introduction to Python Keywords –

  1. Value Keywords: True, False, None
  2. Operator Keywords: and, or, not, in, is
  3. Control Flow Keywords: if, elif, else
  4. Iteration Keywords: for, while, break, continue, else
  5. Structure Keywords: def, class, with, as, pass, lambda
  6. Return Keywords: return, yield
  7. Import Keywords: import, from, as
Trueimportforis
Falsefromwhilenot
Noneinreturnor
globalasifpass
nonlocaldelelseand
tryyieldelifraise
exceptlambdacontinuewith
classdefbreakawait
assertasyncfinally

We can get a full list of Python keywords with the below code –

import keyword
x = keyword.kwlist
print(x)

Result –

['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']

Leave a Reply

Your email address will not be published.