Python List (Part II)

https://miro.medium.com/max/1200/0*jqQkK0u7uH9ZCoDh

Original Source Here

smart and simple

Photo by James Harrison on Unsplash

Let’s learn about indexing and slicing of list

There are two types of index in the list

  • positive index
  • negative index

The positive index always starts from the first element and the negative from the last.

we can directly access elements using their index

my_list[0] --> output: 10
my_list[3] --> output: 40
my_list[-1] --> output: 60
+my_list[4] and my_list[-2] both will point to the same element.

let’s move to Slicing

Slicing is nothing but accessing a specific portion of the list where we can mention from which index we want and up to what index, we can also mention step size which we have seen in part I of the list article.

Always remember the end is exclusive

step size will be 1 by default.

suppose we want to extract the date, month, and year from the given date we can use the slicing concept.

Well, now you don’t have to study slicing again for string, NumPy arrays, or tuple because the same concept and steps are there.

In the next article, we will see functions in the list……..

AI/ML

Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot

%d bloggers like this: