Python is a high-level programming language that provides functionalities for several operations. The keyword
module comes with various methods to manipulate keywords.
The read-only attribute kwlist
returns a list of all keywords reserved for the interpreter.
kwlist = keyword.kwlist
This attribute returns a list of all keywords reserved for the interpreter. If any keywords are planned in future versions, they are included too.
#import moduleimport keyword#print kwlistkwlist = keyword.kwlistprint(kwlist)#intialize test stringsstring = 'This attribute returns a list of all keywords reserved for the interpreter. If any keywords are planned in future versions, they are included too.'string_list = string.split()#check if test strings are present in kwlistfor word in string_list:print(word,': ', word in kwlist)
keyword
module.kwlist
using keyword.kwlist
.string_list
that contains all words of the string.for
loop, all words in the list are checked to see if they belong to kwlist
.string_list
are printed, along with a boolean
value indicating whether they are a reserved keyword or not.