Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "DEDENT" in Python reference?

Tags:

python

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?

like image 487
illiterate Avatar asked Dec 01 '18 10:12

illiterate


1 Answers

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).

like image 188
sepp2k Avatar answered Sep 27 '22 23:09

sepp2k