I'm writing a program which does some code generation to python and need to treat a string differently if it is a python keyword. help(keywords)
prints the python keywords and some extra stuff, but I wonder if there's a pythonic way to get an actual iterable object with these strings in it?
Python list can contain duplicate elements.
What are duplicates in a list? If an integer or string or any items in a list are repeated more than one time, they are duplicates.
In Python, there are approximately around thirty-three (33) keywords, and a few of the keywords generally used in the program coding are break, continue, true, false, and, or, not, for, while, def, class, if, else, elif, import, from, except, exec, print, return, yield, lambda, global, etc.
You are better of using the keyword module
>>> import keyword >>> keyword.kwlist ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With