Return type in list


#1

n = [1,3,5]
del(n[1])
print(n)
result = [1,5]
As per codeacademy del(n[1]) is like .pop in that it will remove the item at the given index, but it won’t return it. what does it mean “it won’t return it” ?


#2

.pop() returns the removed item, in case you need to do something with the removed item this can be very handy

del doesn’t return the removed item

.pop() is a built-in method, just like functions it can use return to hand you something back.


#3

So you mean we can use return statement with .pop() ? Is ti possible? if possible, How can we use it any suggestion


#4

no, return is already used in the .pop() method.

someone wrote a method named .pop() and built it in such a way that it returns the removed element. Now imaging you did that, how could we get the returned value? remember what you learned about return so far