Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Mistaking Dictionary Syntax
00:00
Mistaking Dictionary Syntax. You saw earlier that you could get a SyntaxError if you leave the comma off of a dictionary element. Another form of invalid syntax with Python dictionaries is use of the equals sign to separate keys and values, instead of the colon.
00:22 Once again, the error message is not very helpful. The repeated line and caret, however, are very helpful. They’re pointing right to the problem character.
00:30
This type of issue is common if you confuse Python syntax with that of other programming languages. You’ll also see this if you confuse the act of defining a dictionary with a dict() call.
00:41
To fix this, you could replace the equal sign with a colon, or you can switch to using dict(), as seen here.
00:51
You can always use dict() to define the dictionary if that syntax is more helpful.
Become a Member to join the conversation.