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. This type of issue is common if you confuse Python syntax with that of other programming languages.
00:36
You’ll also see this if you confuse the act of defining a dictionary with a dict()
call. 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.