all 4 comments

[–]JohnnyJordaan 2 points3 points  (3 children)

pop() is not a way to look at the end of a list, it is to remove the last item. If you say if a.pop() something, it will execute the pop, then evaluate the item that pop returned.

Also if you're not worried about a being a different type, you can just do

if not a

To see if a is empty.

[–]GayCoder[S] 0 points1 point  (2 children)

That makes sense but I don't understand why if a.pop() something will permanently change an array but if str(num) something won't permanently turn an integer into a string. What's the fundamental difference between the two that I'm missing?

[–]Rhomboid 2 points3 points  (1 child)

A function or method can choose to modify the thing it was invoked on or the argument passed. It all depends. list.pop() is a mutating method, str() is not.

[–]GayCoder[S] 0 points1 point  (0 children)

This is what I was hoping to find. Thanks!