Sunday, 10 December 2017

List of keywords in Python

Tags


Python keywords are the those reserved words in python which cannot be used as an identifier, function or variable name. These keywords are reserved ones. They have their own pre-defined behavior.

The list of all keywords in python is given here.

There are 33 keywords in Python 3.5. This number can vary in upcoming versions.


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

The above given python keywords may get changed in upcoming versions. Some new keywords might be added or some old keywords might be removed. But you can get the keywords in your python version by using the code given below.


>>> import keyword
>>> print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', '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']


EmoticonEmoticon