Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 6 Online
OpenStudy (anonymous):

pop() is a method of lists...but I learnt that it's different than del because it "returns an arbitrary element from the set". That's what I don't get. What does "returning" the value mean?? I'm new but bear with me :D does it mean that if you pop (an element from the list) whilst printing it, it will print the 'popped' element. [mylist = [0,1,2,3,4,5,6,7,8,9] print mylist.pop(6) And the output would be 6?? That is what returning mean?? Thanks in advance ;)

OpenStudy (anonymous):

http://dpaste.com/796600/ a function usually returns something to the thing that called it

OpenStudy (anonymous):

Well,returning means that `pop()` is actually a function. This function will delete 1 element of a list and return that element. So, if we want we can assign that element to a varible, while `del` only delete that element. like: ``` mynumbers = [1, 3, 5, 7, 9] last = mynumbers.pop() ``` then: ``` print mynumbers >>> [1, 3, 5, 7] print last >>> 9 ``` Nice, right?

OpenStudy (anonymous):

I GOT IT! :D Yeah! Super cool ;D Thank you =)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!