+ 1

Is there a built in method to reverse a string in Python

String = 'hello' , output = 'olleh'

5th Jan 2020, 8:43 PM
Daniel Ukoha
Daniel Ukoha - avatar
4 ответов
+ 3
Just use [::-1]
5th Jan 2020, 10:27 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
mystring1 = "hello world" mystring1 = mystring1[::-1] print(mystring1) # or...using builtins.. mystring2 = "hello world" mystring2 = "".join(reversed(mystring2)) print(mystring2) # or... mystring3 = "hello world" print(*reversed(mystring3), sep='')
5th Jan 2020, 9:03 PM
rodwynnejones
rodwynnejones - avatar
0
Thanks a lot
5th Jan 2020, 10:30 PM
Daniel Ukoha
Daniel Ukoha - avatar
0
print("hello"[::-1])
5th Jan 2020, 10:39 PM
Eduardo Mbogo Nguema
Eduardo Mbogo Nguema - avatar