Python Indentation

Chris Angelico rosuav at gmail.com
Sat Aug 13 13:39:46 EDT 2016


On Sun, Aug 14, 2016 at 3:06 AM, Cai Gengyang <gengyangcai at gmail.com> wrote:
> 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 ?

Yep! That's correct.
ChrisA


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /