List method to delete last element in list as well as all elements


I have an issue with clearing lists. In the current program, I have a method that clears a certain number of lists. This is rather inconvenient since during one part of the program where this method is used, it would be a lot more helpful if it only deleted the last element from the lists. Is there any way in which I can set index numbers as parameters to my method to solve this problem?

The code for the method

def clearLists(self):
    del self.Ans[:]
    del self.masses[:]

Whenever I want to use this method, I merely write self.ClearLists() and it deletes every element in a list.

9/20/2017 3:17:18 PM

you can use lst.pop() or del lst[-1]

12/2/2011 2:54:03 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow