Python Logic Building for Beginners | Python Programming Tutorial 2026

Akansha Yadav shows how to reverse a string in Python using slice notation string[::-1]. The step parameter of -1 moves backwards through the sequence, and the method works with spaces and any character case.
Chapters
Let us see how to reverse a string using the slicing technique. So when it comes to reversing a string, we just need a string first. So we are going to create a variable string and we can store anything that we want in this— uppercases, lowercases, anything it could be. So I'm storing Coding D D Programming as in the value in the string variable. Now next is I'm going to do the slicing. So string square bracket. In square bracket we have to write colon colon minus 1, and that's it. String square bracket colon colon minus 1. Let me remove this equal to. Now this is the exact thing which you need to reverse a string. Now I'm going to simply print it. Print string colon colon minus 1, and then execute it. Now you can see your entire skin string is just reversed, right? String String is reversed with the help of slicing technique. Now let us go through what we are doing. So we have two words, which is Coding Didi, Programming. In this two word we have a space also, so this totally doesn't matter with the method which we have used. So slicing technique I am specifically talking about. Now what we are doing is we are performing an action which is reverse action. It means I want same number of letters, same number of spaces, everything has to be same, but, but I just want it to be in the reverse order. It means G-N-I-M-M-M something, right? So what is slicing? Slicing techniques goes with 3 parameters. So in square brackets, start, stop, step. Start, stop, step is the 3 value. Now we have the colons in between as a separator. It is like a slice, it is like a knife which we use to cut something in day-to-day life. So colon is the same, colon is a slicer. Now start 0, end 0, step -1. If you are thinking it like this, then this is totally wrong because stop cannot be 0. You remember, indexing starts from 0 value in Python. It means indexing starts from 0, but stop cannot be 0 because the last value in any string or any list is always -1. So 0 is— means starting. It means you can write 0 or you can avoid it. If The second parameter is stop, it means ending. So if you are not giving any value, let's say you're not giving, giving start value and you are not giving stop value, it means beginning to ending it will go completely to the entire characters. Then comes the -1. -1 is nothing, we are instructing it to move backwards one step at a time. What -1 is doing? Move backwards one step at the time. Why we are using -1? Because I wanted to go backwards from the last character, not from the beginning. So simply, we are not giving first starting and ending value. We are just saying the step has to be move backward. Start and step are two parameters you can mention or you cannot. It is totally up to you. All three values can be optional. So when we are giving no value instead of start and stop, it means clearly we are saying that from the beginning to the ending of the string you have to go, from the beginning to the ending. But what do you have to exactly do is you have to move backwards. It means go from this last and then move backwards one at a time. It means this is how it is gonna print G-N-I-M-M. So it is very simple, you just have to understand this concept called slicing.










