Given a string, write a Python program that checks if the given string is keyword or not.
- Keywords are reserved words which cannot be used as variable names.
- There are 33 keywords in Python programming language.(in python 3.6.2 version)
Input: str = "geeks" Output: geeks is not a keyword Input: str = "for" Output: for is a keyword
We can always get the list of keywords in the current Python version using
kwlist method in keyword module.
No. of keywords present in current version : 33
[‘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’]
Below is the Python code to check if a given string is Keyword or not:
- How to check if a string is a valid keyword in Python?
- Python program to check if a string is palindrome or not
- Python program to check if string is empty or not
- Python program to check if given string is pangram
- Python program to check if a string contains all unique characters
- Python program to check if given string is vowel Palindrome
- Python | Check if given string can be formed by concatenating string elements of list
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Check if string ends with any string in given list
- Python | Check if a given string is binary string or not
- Program to check if a string contains any special character
- Python | Check for URL in a String
- Python | Check whether string contains only numbers or not
- Python | Check if given string is numeric or not
- Python | Check for spaces in string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.