• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
August 16, 2022 |1.6K Views
Get First and Last Elements of a List in Python Program
  Share   Like
Description
Discussion

In this video, we will learn write a python program to get the first and last elements of a list. 

Below is the list of approaches that we will cover: 
1. Getting the elements using list index. 
2. Getting the element using list slicing 

To get the element we are using list indexing in which we can pass the 0 index number and length of list -1 to get the last element of the list, we can also use the negative indexing to get the element from the list. This is most naïve method to achieve this particular task one can think of. 

The another method is using list slicing, It technique to perform the particular task of getting first and last element. We can use step of whole list to skip to the last element after the first element.

Python program to get the first and last elements of a list:
https://www.geeksforgeeks.org/python-get-first-and-last-elements-of-a-list/

Read More