0
In which case do we use 2 colons i.e. [::] in list function ? Is this what we call stepper ?
We can also use these 2 colons for reversing a string in list ? For eg. [::-1] This will reverse the string. Is it correct that same way we can reverse it with the reverse method? For eg. sample = input(" ")[::-1] Above code will reverse the string. And the same way with reverse method also, can we do the same ? For eg. sample = input(" ") sample.reverse() print(sample) Could someone please help me out with this uncertainty regarding :: and reversing a string ? Thank you in advance!
2 Antworten
0
What exactly are you unsure about? Have you tried it out in the playground?
indexing -- <iterable>[start:stop:step]
0
Slick I was unsure about the slicing. But abol cleared it by sharing his post. Thanks. But still there are still 2 doubts. First is reversing a string. Is it possible to do it without using the reverse. method?
Second is agaim about slicing but using - (minus sign).
Could you please give me an example with explanation for slicing with minus at the end?
I would be highly obliged.