String Slicing using Negative Indices: Behind the Scenes
📌 String Slicing using Negative Indices: Behind the Scenes ⭐️ Welcome to this tutorial 👋 Now you will learn how to slice strings using negative Indices. Let's begin! You already know that strings have an internal structure that is very similar to a grid (please read this tutorial first if you are not familiar with this. You can also visualize it below). But did you know that you can also refer to indices using negative numbers? Yes, this surprised me very much as well! 😱 This is the grid structure of the "Hello, World!" string with its corresponding positive indices: You can now see the grid structure in the diagram below, with the corresponding negative indices: Notice that now we are counting backwards, starting from -1 for the last index all the way to -13 for the first index. We subtract one when we move one index to the left (or add one when we move one index to the right, which is equivalent). ...