- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements