 What's up guys, Root of the Null here and we're looking at some more Python code. We've been looking at lists, strings, and tuples recently and one of the really interesting tactics or techniques we've been looking at is called indexing. Now indexing is when you use a numbered element in like a list or a string to be able to get the character or the item that is at that position inside the object whether it be a list or a string or a tuple. So now one of the other really fascinating things you can do with this is something called slicing. Now slicing allows you to get multiple pieces of information by using a range when you index something. So let's get idle started and I'll show you what I mean. I'm gonna be working at the interactive shell today. This isn't really an example that I have a good idea for for building a new script. So please bear with me and we'll try and see what we can do here. Let's get started with the string first of all. Let's do this is a bad word because I wanted to do something different from saying this is a string. So now we've got a string, okay, and we can index this or retrieve values from it from any specific character. Let's let's say we want t, h, i, s, that's gonna be four, five, and six. Let's say we want to get that sixth character, that i. Remember that white space is considered a character so spaces, tab keys, they're all a character. They're all part of the index. So if we do six, we should get i. Oh, I counted wrong because you know what? This is a good thing to mention. We have we have to start at zero because we're we're treating this like a computer. So zero, one, two, three, four, five, and six is gonna be s. i is number five because we're counting from that zero to whatever we want bit. We have to subtract one from what we would usually expect. So string five is gonna get us i. So now what if we did a string five and we'll use some slicing here. Slicing is represented inside the index box that we've got going on here and you use a colon and then you use a range or how far you want it to go to. So you can go to let's say let's say eight so we can get is, is and that space afterwards. So we've got this is five, this is six, and this is seven. So eight is eight is a that that's strange isn't it? When you think about it really isn't though because we're using that whole like less than idea we want to have these things there in the range. We have these three characters eight minus five is eight. I'm eight minus five is three. Damn I'm retarded. Eight minus five is three so we're gonna be returned three characters. We have i, s, and that space. So now we could return this with any sort of thing though. We could have string, let's say zero and maybe ten. I don't know. That's a good idea. This is a and we have that last bit cut off. What if we did, we can run functions inside our index too. We can go like zero to the length of the of string. This is kind of counterintuitive though because we're getting the entire string here. This is a bad word but it returns the whole thing nonetheless. That's another thing to mention too. If we don't supply a beginning or an ending piece of the range, if we just apply that semicolon, it'll return the whole string. Now when you think of that philosophy, if you don't supply things like a beginning or an ending number, you could go for let's say how about we use five, we can get is, into the end of the string because we're not gonna supply an ending number. So we'll start from character five and continue onward. This is a bad word. We've cut out the word this in the space. Now this can work both ways too. We can do let's say we can go from ten, we can go from the beginning up until ten. So this is a and including the space. Now what if we had a little bit more of an adventure with this though? We can do string and let's get a colon here so we get the entire string. That's what we want. But if we add another colon, we can supply a step or just like we did in that range function, we can supply how much we want to increment by each time we're going to a different term. So let's increment by two. Oh, I screwed up my syntax there. My apologies. So let's go from the beginning to the end, except we'll increment by two. So this is a bad word. I would have guessed that, but you guys didn't give me a chance. But yeah, see it's going to skip all those words that are separated by that too. So this H, not going to see it. This S, not going to see it. This I, not going to see it. This space, not going to see it. This other space, not going to see it. Because we're stepping by two, going from beginning to end. So when we actually look at this though, we are going from what is the length of the string, by the way? Let's find out. We'll use our LAN function, 19. So if we do string index from zero to 19 to two, you get to a sabbdware. Except you don't have to be using the entire string. Remember, you can do from five to eight and you can use those two. Just like we did up here, except we're using that step of two. So now let's look at this in a different way, because remember we were able to index things with negative numbers. We could do reverse searching, remember? If we do string negative, let's say negative one to the end, it'll go that period. Negative one is going to be, let's see, remember that last bit here, it's going to go from that period to the end obviously. So if we do string, let's say negative one to, from the beginning to negative one, we get the entire thing except that period, because we're starting the cursor. If you think of it as like an imaginary cursor, we're right here before the period and we're getting everything from the beginning. Okay, so that's an interesting way to think about it. What if we tried it with a negative step? Would that work? I'll be honest, I have not tried this. Let's see what we can do here. Let's get negative two. So I'm thinking that it'll start a skew, one, two, three, four, five. Let's try negative five, I'm thinking. So we can get that word and let's do negative 15. Oh, what am I doing here? Oh, that's right, I think. I don't know. I don't know. I'm getting nervous, I don't know what to say anymore. We start from negative five, we're going negative five to the end of Okay, so we need a bigger number here. Because we have that negative number, it's going to go from there to anywhere else. So if we start from, we have to have the bigger number here. Let's start from negative 15, and then that negative five, we're going to go is a bad. And what if we tried with a negative step? Would it yell at us? No, it doesn't do anything because it can't. Interesting, very interesting. If you just applied one as a step, that's the default. But yeah, okay. So yeah, that's kind of the point that I've been trying to get across though here. You can subtract or at least get multiple pieces of information out from an object. Let's try with a list. Let's try list equals a This is a bad word. I'm so original. So now we've got list. List is this is a bad word and we can get things out of that let's say 224. So we will get only two and three though because we remember we can look over this in the side notes because we're starting at two and we want to go until anything there's less than less than four we're going to get the indexes is this is zero is this one is two for I'm sorry bad is three and word is four so now we've got if we're getting two and three out of this out of this list we're going to have a and then bad a bad exactly what we returned we can do this again with negative things native four to negative one is a bad because we're getting here here so this makes sense right I know it's complex when you try and think of it with negative numbers and that sort of thing but you can do this with lists you can do this with tuples you can do this with strings and it might help you when you're trying to get pieces out pieces of the information out but not retrieving all of it but not retrieving just one bit so hey that's all I've got for you guys today thank you for watching thank you for listening thank you for sticking by me but uh thanks again guys I'll see you in the next tutorial