The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

problem in python programming

problem in python programming

1
Vote
1
Answer

while doing assigned question from python boot camp i came through a problem of reversing an string
solution given is – 
print(‘Enter a string’)
x=input()
y=x[::-1]
print(y)
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)
Thank you!:) 

1 Answer

365 Team
0
Votes

Hi Prafful
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:
https://www.educative.io/edpresso/how-do-you-reverse-a-string-in-python

Best,
Eli

×
LAST CHANCE
Ready to Learn Data Science?
50% OFF