Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different indentation no error in python

password = raw_input("Enter password: ")
if password == "1234":
  print "You logged in correctly!"
else:
    print "GTFO"

Though i give different indentations the code is working fine i'm unable to figure it out.

like image 355
drj Avatar asked Aug 04 '26 23:08

drj


1 Answers

it will not be flagged as as IndentationError, sine any block of statement has to have at lease 1 space of indent

here your if and else are two different blocks, so it was indented anyway so the interpreter throws no error

if True:
 print 
elif True:
  print 
elif True:
   print 
elif True:
     print 
else:
         print

This will work without any problem

But if I try the following I will get IndendationError

if True:

    print ""
      print ""  # has different Indentation
    print ""
like image 164
Siva Cn Avatar answered Aug 06 '26 12:08

Siva Cn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!