The Python module "keyword" has function iskeyword(). It can be used to determine whether a string is a Python keyword or not.
Here is an example:
>>> import keyword>>> str="None">>> keyword.iskeyword(str)True>>> str="hello">>> keyword.iskeyword(str)False