Why does Python raise TypeError rather than SyntaxError?

前端 未结 2 1702
一个人的身影
一个人的身影 2020-12-30 18:59

A question purely for curiosity\'s sake. This is obviously invalid syntax:

foo = {}
foo[\'bar\': \'baz\']

It\'s obvious what happened, the

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 19:37

    Using the colon in an indexing operation generates a slice object, which is not hashable.

提交回复
热议问题