I'm trying to figure out why some statements require and RETURN and others do not? Like below, I wrote this and l1.append(val) doesn't need a return but for example l1[val] does?
Does it just depend on the variable?
L = [1,3,5,7,9,11, 2]
print 'Original List =', L
def change_list(l1, val, decision):
if decision == 'append':
return l1[val]
elif decision == 'ret':
l1.append(val)
elif decision == 'instance':
return l1.count(val)
elif decision == 'sort':
l1.sort()
return l1
res=change_list(L, 2, 'append')
print 'Output =', res
However if I change it to the following (remove the return) it breaks! Wh does this happen given some of the conditions need a return to work, some do not?:
L = [1,3,5,7,9,11, 2]
print 'Original List =', L
def change_list(l1, val, decision):
if decision == 'append':
l1[val]
elif decision == 'ret':
l1.append(val)
elif decision == 'instance':
return l1.count(val)
elif decision == 'sort':
l1.sort()
return l1
res=change_list(L, 2, 'append')
print 'Output =', res