What do the Python VSCode syntax colors mean?

Viewed 2441

VSCode has syntax highlighting for the Python language. I can't find any explanation for how each token is classified and organized into colors.

Specifically, why are some keywords the same color, but some are different.

Looking at this code:

Code example in VSCode

for...in shows the keywords as the same color, but if...in shows the keywords as different colors. Why does in change color? What determines if a keyword is purple or blue or something else?

Finally, is there an exhaustive list or chart for how keywords are organized?

Update

From the first link in @JillCheng's answer I found the Scope Inspector, which can be enabled by running Developer: Inspect Editor Tokens and Scopes in the command palette. This will then show how the currently selected text was tokenized.

for...in shows both keywords are tokenized as keyword.control.flow.python.

if...in shows if as keyword.control.flow.python and in as keyword.operator.logical.python.

2 Answers

They are not the same in. The first is used to iterate while the second is an operator.

Related