I’m learning the foundations of programming in Python. I’m just curious about using indexing [::]. I understand the ability to pull out sub sections in steps, forwards and backwards, but just wondering what actually you can do with it? Why would you want to pull out every other letter? What’s it’s purpose in an algorithm? What are the real world applications in programming, or is it just a another tool in the tool box?
It’s just another tool. I can imagine uses for this with strings, for
specially formatted ones. Perhaps ethernet addresses, which look like
However, the start:end:step form is generic indexing, and applies to
any sequence, not just strings. So also lists. There are situations
where that is useful.
Explicitly using the “step” part is rare, and usually -1 for counting
backwards. But it is just part of the toolbox, to be used when required.
Cameron Simpson firstname.lastname@example.org
Thank you Cameron,
That’s what I thought, indexing would be more useful to grab specific integer characters from a network or database.