Skip to content

Commit 37e520e

Browse files
check if a string is a valid keyword in Python
In programming, a keyword is a “reserved word” by the language which convey a special meaning to the interpreter. It may be a command or a parameter. Keywords cannot be used as a variable name in the program snippet. Keywords in Python: Python language also reserves some of keywords that convey special meaning. Knowledge of these is necessary part of learning this language. Below is list of keywords registered by python .
1 parent 99cf7d7 commit 37e520e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Instead of writing this massive Python code we can also code this in a different way
2+
3+
#Python code to demonstrate working of iskeyword()
4+
5+
# importing "keyword" for keyword operations
6+
import keyword
7+
import keyword
8+
# initializing strings for testing while putting them in an array
9+
keys = ["for", "while", "tanisha", "break", "sky",
10+
"elif", "assert", "pulkit", "lambda", "else", "sakshar"]
11+
12+
for i in range(len(keys)):
13+
# checking which are keywords
14+
if keyword.iskeyword(keys[i]):
15+
print(keys[i] + " is python keyword")
16+
else:
17+
print(keys[i] + " is not a python keyword")

0 commit comments

Comments
 (0)