I’m new to python. Look at this script please:
def myfunc(*args):
print len(args)
if args == 3:
for arg in args:
print arg
else:
print "exit"
a, b, c = 1, 2, 3
myfunc(a, b, c)
As you can see, the number of arguments passing to function is three. Now condition args==3 is True but the else portion is executed. While on other hand if if condition is false then that portion of code is executed and else is skipped.
Can you explain why the if statement is executed on False condition ?
I think you must be doing
len(args)==3instead ofargs==3:the condition
args==3is never going to be true asargsbecomes a tuple inside the function.so even if you pass
myfunc(3), then also you’ll be matching(3,)==3, which isFalse.