Why do I get a syntax error when everything seems to be fine?

I'm starting with python code and when doing some exercises one of them gave me a syntax error:

fruit_dict= {} fruit_dict['apple'] = 10 fruit_dict['pear'] = 3 fruit_dict['walnut'] = 216
fruit_dict.keys()
File "<ipython-input-24-853fedccd771>", line 1
    fruit_dict={} fruit_dict['apple'] = 10 fruit_dict['pear'] = 3 fruit_dict['walnut'] = 216
                  ^
SyntaxError: invalid syntax

I've tried many things but nothing seems to work, if someone can help me with this I really appreciate it.

Upvotes: 0

Views: 190

Answers (1)

DevLounge
DevLounge

Reputation: 8447

You are getting this because you perform all your assignments on the same line. This is not possible in python.

fruit_dict = {}

fruit_dict['apple'] = 10
fruit_dict['pear'] = 3
fruit_dict['walnut'] = 216

fruit_dict.keys()

This will work.

Upvotes: 3

Related Questions