while doing assigned question from python boot camp i came through a problem of reversing an string
solution given is –
print(‘Enter a string’)
i couldn’t understand the y=x[::-1] command.
can you please explain more about it.(wasn’t able to find this command on internet so if you have any link please share, i will refer that)
thanks for reaching out!
This particular example is used to reverse a string using a slicer. The -1 is the step, so at each iteration we’re going back one element at a time. Here we haven’t specified the length of the interval to be reversed, so by default the whole string is reversed.
Here is a link with more on the topic of slicing: