S
S
sswwssww2019-12-14 11:28:18
Python
sswwssww, 2019-12-14 11:28:18

Why can't **kwargs accept a dictionary with an int key?

def tst_func(**kwargs):
    print(kwargs)
    
d = dict((('t', 2), (2, 2),))
print(d)
tst_func(**d)

Why doesn't it work?
Gives an error message:
Traceback (most recent call last):
File "main.py", line 22, in
tst_func(**d)
TypeError: tst_func() keywords must be strings

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2019-12-14
@sswwssww

Because, in python functions, a number cannot be a name for an argument. You are clearly written about this in an error

A
antonksa, 2019-12-14
@antonksa

sswwssww , you yourself think ... What you are trying to do is equivalent How do you even imagine it?

print(2)
>>> asdf
type(2)
>>> str

like this?!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question