The language is python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

The language is python

Reversing a string is a common task during coding interviews. Given a string as input, output its reverse. Sample Input hello world Sample Output dlrow olleh

3rd Mar 2022, 9:12 PM
Ali Alrahem
Ali Alrahem - avatar
14 Answers
+ 8
>>> 'hello world'[::-1] 'dlrow olleh' >>> ''.join(reversed('a string')) 'gnirts a'
4th Mar 2022, 4:43 AM
Vaibhav
Vaibhav - avatar
+ 2
What are you talking about, here is a very simple example: https://code.sololearn.com/cPX6pKsVCSTW/?ref=app
4th Mar 2022, 1:02 AM
William Jönsson
William Jönsson - avatar
+ 1
print(input()[::-1]) # no troll this time :)
4th Mar 2022, 1:23 AM
Ion Kare
Ion Kare - avatar
+ 1
To reverse a string take a look at the following code : string = "hello world" print(string[::-1]) we can reverse a string by using list slicing. string[start:stop:step] Here string[::-1] As the first and second numbers(i.e start and stop numbers) in the above slice are not mentioned it's taken to be from start to end and as the step is -1 it prints the string from end to start By this we can get a reversed string. so finally the output would look like: dlrow olleh Hope you understood it😀
4th Mar 2022, 5:51 AM
Sai Krishna
Sai Krishna - avatar
+ 1
U have all the time u need.
4th Mar 2022, 1:39 PM
Oma Falk
Oma Falk - avatar
0
Yes you completed over 20 courses
3rd Mar 2022, 9:41 PM
Ion Kare
Ion Kare - avatar
0
To further explain how it works: When splicing a list or in this case a string the syntax is somestring[start:stop:step]. We can omit the first two parameters since we want to go over all the elements which leaves us with step. By taking a negative step size we will go backwards.
4th Mar 2022, 1:12 AM
William Jönsson
William Jönsson - avatar
0
Thank you it work no bug
4th Mar 2022, 1:32 AM
Ali Alrahem
Ali Alrahem - avatar
0
I just start learn python and not everyone can understand everything there are many hundred of beganer developer has hard time to understand html or css or javascript or any languge not evey lunguge is easy to understand
4th Mar 2022, 12:36 PM
Ali Alrahem
Ali Alrahem - avatar
- 1
fun main() = println("hello world".reversed()) Is this python ? ;o
3rd Mar 2022, 10:04 PM
Ion Kare
Ion Kare - avatar
- 1
There is a syntex error it is a python but it is wrong
4th Mar 2022, 12:49 AM
Ali Alrahem
Ali Alrahem - avatar
- 2
I am tryint to a ask a questionl If you do not wont to answer or expain do not post anything
3rd Mar 2022, 9:47 PM
Ali Alrahem
Ali Alrahem - avatar
- 2
It never work there is abug if you declare it with txt and print it show error txt = "Hello World" print(txt[::-1])
4th Mar 2022, 1:21 AM
Ali Alrahem
Ali Alrahem - avatar