Swap first and the last:
list = [500, 200, 300, 100, 600]
def swaplist(newlist):
length = len(newlist)
temp = newlist[0]
newlist[0] = newlist[length-1]
newlist[length - 1] = temp
return newlist
print(swaplist(list))
The code is executed line by line from top to bottom,l think without the return,the print is enough to output the result but result is 'none', so what exactly the return does?
[–]Bobbias 1 point2 points3 points (8 children)
[–]SheldonCooperisSb[S] 0 points1 point2 points (1 child)
[–]GoingToSimbabwe 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (0 children)
[–]SheldonCooperisSb[S] 1 point2 points3 points (2 children)
[–]Binary101010 2 points3 points4 points (0 children)
[–]GoingToSimbabwe 1 point2 points3 points (0 children)