Indexing is a way to access a specific element in a iteritable sequence.
To access a specific element in this list, we’d do:
The ‘…” is representing the position of element we want to access, so for example:
This has the value of “World!” as it’s the second element in the list. In python we count from 0 hence this being 1 and not 2. Indexing isn’t limited to lists, we can use it on anything that’s iteritable, such as strings…
We also have something named slicing that allows us to do a bunch of neat operations to a iteritable sequence.
Unlike in indexing, we count from -1 not 0. Running “m[-2]” would give us Hello. We can also use the “:” keyword:
I won’t be explaining much as it’s pretty much said in the comments provided.