SaiVamshi Dobbali SaiVamshi Dobbali - 3 months ago 13
Python Question

what is logical AND doing here ,is it catching error

If I run

script.py
without passing argument it shows

error: list index out of bounds


script.py:

from sys import *
if argv[1]=="what":
print "done"
else:
pass


If I run
script1.py
without passing errors it doesn't show error

script1.py:

from sys import *
if len(argv)==2 and argv[1]=="what":
print "done"
else:
pass


What is logical
AND
doing?

Answer
if len(argv)==2 and argv[1]=="what"

"Logical and" evaluate the left statement, then the right statement.

If the left statement return "false" then the right statement will not be evaluated.

Comments