+ 1

Is there any function/method to reverse the string in python?

7th Jul 2019, 1:56 PM
Shubham Tandale
Shubham Tandale - avatar
6 Respostas
+ 2
You can use this: join(reversed(str)), but it is way simpler to just use the previous method
7th Jul 2019, 2:23 PM
Airree
Airree - avatar
+ 1
Yes. str = str[::-1]
7th Jul 2019, 2:04 PM
Airree
Airree - avatar
+ 1
def reverse(str): return str[::-1]
7th Jul 2019, 2:20 PM
Airree
Airree - avatar
+ 1
long story short, there is (at least i think so) no built in function for that. You can use list methods s = list("HelloWorld") for i in range(len(s)): s.insert(0,s.pop(i)) print("".join(s)) or slice string as Airree said
7th Jul 2019, 8:35 PM
Choe
Choe - avatar
0
I mean function
7th Jul 2019, 2:19 PM
Shubham Tandale
Shubham Tandale - avatar
0
No in built function?
7th Jul 2019, 2:21 PM
Shubham Tandale
Shubham Tandale - avatar