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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.