logo-MindMajix
PostPythonPython
s
sreelu 123

Posted on 20th June 2024|15 views

0
votes

Last Element Of List Python

How can I get the last element of the list in python?

1 answers
Answers
P
naseer mohammad

Posted on 20th June 2024| views

You can simply find the last digit of a list by using [] operator just like this.

test_list = [1, 3, 8, 6, 4, 5]

# printing original list 

print ("This is the original list : " + str(test_list))

# using len - 1 index to print last list element

print ("Finding the last element by using [ len -1 ] is : "

           + str(test_list[len(test_list) -1]))

# using -1 index to print last list element

print ("Finding the last element by using [ -1 ] is : "

                      + str(test_list[-1]))

Output:

This is the original list : [1, 3, 8, 6, 4, 5]

Finding the last element by using [ len -1 ] is : 5

Finding the last element by using [ -1 ] is : 5

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number