
- 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
Python program to check if a given string is Keyword or not
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a number, we need to check that the number is a power of two or not.
Keywords are the special words reserved by any language with specific usage and cannot be used as an identifier.
To check whether the given string is a keyword we used the keyword module as discussed below.
Example
# keyword module import keyword # Function def isKeyword(word) : # list of all keywords keyword_list = keyword.kwlist # check the presence if word in keyword_list : return "Yes" else : return "No" # main if __name__ == "__main__" : print(isKeyword("tut")) print(isKeyword("or"))
Output
No Yes
Conclusion
In this article, we have learned how we can check the string is a keyword or not.
- Related Articles
- C program to check if a given string is Keyword or not?
- Swift Program to check if a given string is Keyword or not
- How to check if a given word is a Python keyword or not?
- Python - Check if a given string is binary string or not
- Python program to check if a string is palindrome or not
- Python program to check whether a given string is Heterogram or not
- Program to check given string is pangram or not in Python
- Python program to check if the string is empty or not
- Program to check given string is anagram of palindromic or not in Python
- Java Program to check if a string is empty or not
- C# program to check if a string is palindrome or not
- Java program to check whether a given string is Heterogram or not
- C# program to check whether a given string is Heterogram or not
- Swift Program to check whether a given string is Heterogram or not
- C# program to check if string is panagram or not

Advertisements