", l...">

Adding "class" as dict key

I can do it:

{'class': 'foo'}

      

But when I do this:

dict(class='foo')

      

I get:

File "<stdin>", line 1
     {'class':}
             ^
SyntaxError: invalid syntax

      

Why can't python use a "class" like ** kwarg? It can also easily use list, int, len ... as keyword arguments.

+3


source to share


1 answer


list

, int

and len

are not keywords, they are normal identifiers. class

- keyword .



+14


source







All Articles