Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of python keywords [duplicate]

Tags:

python

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?

like image 614
Mike Vella Avatar asked Jan 30 '13 02:01

Mike Vella


People also ask

Can Python list have duplicates?

Python list can contain duplicate elements.

Can a list have duplicates?

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.

What are the 33 keywords in Python?

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.


1 Answers

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'] 
like image 98
Abhijit Avatar answered Sep 28 '22 10:09

Abhijit