
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to check if a given word is a Python keyword or not?
In this program, we will check whether a given word is a python keyword or not. To do so, we will use the function iskeyword() from the keyword library.
Algorithm
Step 1: Import keyboard. Step 2: Check if the given string is a keyword or not.
Example Code
import keyword words = ["city", "music", "in", "if"] for word in words: if keyword.iskeyword(word): print("{} is a keyword".format(word)) else: print("{} is not a keyword".format(word))
Output
city is not a keyword music is not a keyword in is a keyword if is a keyword
- Related Articles
- Python program to check if a given string is Keyword or not
- C program to check if a given string is Keyword or not?
- Swift Program to check if a given string is Keyword or not
- Check if a word exists in a grid or not in Python
- Python - Check if a given string is binary string or not
- Check if a given graph is tree or not
- How to check if a string is a valid keyword in Python?
- JavaScript program to check if a given matrix is sparse or not
- Python program to check if a string is palindrome or not
- Python program to check if a number is Prime or not
- How to check if a file exists or not using Python?
- Check if given number is Emirp Number or not in Python
- Python program to check whether a given string is Heterogram or not
- Check if a given matrix is sparse or not in C++
- Check if a given number is sparse or not in C++

Advertisements