1

I have found that these two statements don't raise any SyntaxErrors or exception

d = {}
d["a"]: 1

The suspect line is d["a"]: 1. At the very least, I would have expected a KeyError on "a". Furthermore, I can't figure out which compound statement (if any) this satisfies https://docs.python.org/3/reference/compound_stmts.html

If we change the statement to

d["a"]: print(1)

We see the "1" is printed. What behavior should be expected from this kind of colon use? Or, is this an irregularity with python?

Side Note: I'm not trying to use this line, it was discovered by accident. I'm just curious what is happening and why.

ACEnglish
  • 95
  • 2
  • 10

0 Answers0