Python Indentation

Cai Gengyang gengyangcai at gmail.com
Sat Aug 13 13:06:32 EDT 2016


Oh ok, so for the first block , it works because the indentation is the same for all 3 "print" statements , i.e. the indentation is 4 spaces for each of the 3 print statements.

if a == 1: 
    print("If a is one, this will print.") 
    print("So will this.") 
    print("And this.") 
  
print("This will always print because it is not indented.") 

For the 2nd block of code, it doesn't work because the indentation is different, 2 spaces for the first statement, 5 for the 2nd statement and 4 for the 3rd statement.

if a == 1: 
  print("Indented two spaces.") 
     print("Indented four. This will generate an error.") 
    print("The computer will want you to make up your mind.") 

Am i correct ?







On Saturday, August 13, 2016 at 7:12:19 PM UTC+8, Marko Rauhamaa wrote:
> Cai Gengyang <gengyangcai at gmail.com>:
> 
> > Can someone explain in layman's terms what indentation is
> 
> Indentation means the number space (" ") characters in the beginning of a
> line.
> 
> A sequence of lines that have the same indentation belong to the same
> block of statements.
> 
> 
> Marko



More information about the Python-list mailing list