- 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
14 odpowiedzi
+ 8
>>> 'hello world'[::-1]
'dlrow olleh'
>>> ''.join(reversed('a string'))
'gnirts a'
+ 2
What are you talking about, here is a very simple example: https://code.sololearn.com/cPX6pKsVCSTW/?ref=app
+ 1
print(input()[::-1])
# no troll this time :)
+ 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😀
+ 1
U have all the time u need.
0
Yes
you completed over 20 courses
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.
0
Thank you it work no bug
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
- 1
fun main() = println("hello world".reversed())
Is this python ? ;o
- 1
There is a syntex error it is a python but it is wrong
- 2
I am tryint to a ask a questionl
If you do not wont to answer or expain do not post anything
- 2
It never work there is abug if you declare it with txt and print it show error
txt = "Hello World"
print(txt[::-1])