Why is print (* * data) reporting an error instead of displaying the appearance after unpacking

data = {‘aaa’:‘a’,‘bbb’:‘b’}
print(**data)
str1 = ‘{aaa} = {bbb}’.format(**data)
print(str1)

result:
Traceback (most recent call last):
File “D:\pythonProject4\20231030.py”, line 29, in
print(**data)
TypeError: ‘aaa’ is an invalid keyword argument for print()

What should I write if I want to look at the unpacked appearance in the dict?

Thanks.

What are you hoping to see?

print(**data) is telling the interpreter “call the print function and give it keyword arguments from this dictionary.” It translates to print(aaa='b', bbb='b') which is why you get the error you see: print does not have a keyword argument aaa.

If you just print(data) you’ll get a representation of the dictionary, which will look a lot like the code you used to create it.

What I want to see is print (aaa='b ', bbb=‘b’)

Thanks.

you can use comprehension to format a list of strings, then join and print
print(','.join([f"{k}='{v}'" for k,v in data.items()]))
will print
aaa='a',bbb='b'

If you do just print(data), exactly what is wrong about the result?