I was exploring different ways to create a dictionary in Python 3 (3.11.1). ChatGPT suggested that I can create a dictionary by using the following syntax:
my_dict = dict('key1'='value1', 'key2'='value2', 'key3'='value3')
I tried this in IDLE, but I am getting SyntaxError: expression cannot contain assignment, perhaps you meant "=="?.
To confirm if ChatGPT may have suggested the wrong method, I asked the same question with Google Bard. Ever Bard is replying that this method can be used to create a dictionary. Am I missing something?
>Solution :
Hey don’t give the key1 and key2 and key3 quotes. key names should not be in quotes then it will work
my_dict = dict(key1='value1', key2='value2', key3='value3')
print (my_dict)


