Getting the last element of a list

后端 未结 12 1270
一向
一向 2020-11-22 04:58

In Python, how do you get the last element of a list?

12条回答
  •  [愿得一人]
    2020-11-22 05:53

    The simplest way to display last element in python is

    >>> list[-1:] # returns indexed value
        [3]
    >>> list[-1]  # returns value
        3
    

    there are many other method to achieve such a goal but these are short and sweet to use.

提交回复
热议问题