World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITian's, only for AI Learners.
How to handled whitespaces in python?
which is the leftmost position. Whenever a nested block begins, the new indentation level is pushed on the stack,
and an "INDENT" token is inserted into the token stream which is passed to the parser. There can never be more
than one "INDENT" token in a row ( IndentationError ).
if foo: if bar: x = 42 else: print foo
is analyzed as:
<if> <foo> <:>  <INDENT> <if> <bar> <:> [0, 4] <INDENT> <x> <=> <42> [0, 4, 8] <DEDENT> <DEDENT> <else> <:>  <INDENT> <print> <foo> [0, 2] <DEDENT>
The parser than handles the "INDENT" and "DEDENT" tokens as block delimiters.