Python – Why ‘item[“Error”] : ‘message”‘ NOT a syntax error in python 3. 6?

Why ‘item[“Error”] : ‘message”‘ NOT a syntax error in python 3. 6?… here is a solution to the problem.

Why ‘item[“Error”] : ‘message”‘ NOT a syntax error in python 3. 6?

I found a bug in the code I wrote tonight:

item["error"]: "message"

Instead of:

item["error"] = "message"

What I can’t figure out is why the original line didn’t cause a syntax error. What’s going on there? This is not in the dict statement; This is just a regular line of standalone code.

Solution

You accidentally < a href="https://docs.python.org/3/whatsnew/3.6.html#pep-526-syntax-for-variable-annotations" rel="noreferrer noopener nofollow">annotated item ["error"], the value is “message". (What this actually means depends on the code that handles the comments, and by default there is nothing.) Variable annotations are a new feature in Python 3.6.

Related Problems and Solutions