5
votes

https://docs.python.org/3/reference/compound_stmts.html#grammar-token-suite

suite ::= stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT

I can understand the 'DEDENT' word as "Dedent Region" in IDLE(Ctrl+[), But I can't understand the 'detent' appear in python reference document, is "DEDENT" one special character?

1
AFAIK dedent simply means outdent (opposite of indent).mkam

1 Answers

14
votes

It's not a character per se - it is a token that represents the fact that the current line is indented by less spaces than the one before.

So for example the code:

foo
if bar:
  bay
baz

would be tokenized as ID(foo), NEWLINE, IF, ID(bar), COLON, NEWLINE, INDENT, ID(bay), NEWLINE, DEDENT, ID(baz).