Indentation example?

Steven D'Aprano steve at pearwood.info
Sun Jun 12 12:06:02 EDT 2016


On Mon, 13 Jun 2016 01:10 am, ICT Ezy wrote:

> Pl explain with an example the following phase
> "Indentation cannot be split over multiple physical lines using
> backslashes; the whitespace up to the first backslash determines the
> indentation" (in 2.1.8. Indentation of Tutorial.) I want to teach my
> student that point using some examples. Pl help me any body?


Good indentation:

def function():
    # four spaces per indent
    print("hello")
    print("goodbye")


Bad indentation:

def function():
    # four spaces per indent
    print("hello")  # four spaces
  \
  print("goodbye")  # two spaces, then backslash, then two more


The second example will be a SyntaxError.



-- 
Steven




More information about the Python-list mailing list