Conceptual remind/clarification question UNIT 7 part 4. Removing elements from lists


Conceptual question please.

Would someone discuss the difference between "return" and "print" please. I am still confused how they differ or how those commands interact with a given code.

My confusion came up in UNIT 7 part 4. Removing elements from lists

a) n.pop(index) will remove the item at index from the list and return it to you
b) n.remove(item) will remove the actual item if it finds it:
c) del(n[1]) is like .pop in that it will remove the item at the given index, but it won't return it

If you remove an item from a list what does it mean "n.pop(index)" can return the item to me/you?
If I use "del(n[1])" how come the item won't be returned?

If I print a list after "n.pop(index)" does that mean I can access the item i removed later (the item can still be returned)?
What am I printing after I use "del(n[1])"?

Thank you for your time!


lets create a function which returns something:

def example():
    return "returning"
result = example()
print result

see how the example function returns something? It literately gives you something in return, which you can store in a variable, or print directly.

so pop is a built in function, which returns the item you remove from the list. So you get the removed items.

because the del function works very different. it removes the list item from the list


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.