Jump to content

Last element

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
webmag

webmag

    Newbie

  • Members
  • Pip
  • 1 posts
How to get last element in python?

#2
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
Hi,
The simplest way is:
your_var[-1]
But you can also try:
your_var.pop()

Quote

Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Python Library Reference.)