What is reversed function in Python? s= reversed("Hello World!") print(s) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is reversed function in Python? s= reversed("Hello World!") print(s)

s= reversed("Hello World!") print(s)

6th Jul 2021, 8:12 AM
Zahed Shaikh
Zahed Shaikh - avatar
3 Answers
+ 3
reversed() is analogous to sorted(). If you run this code, have a look at the last paragraph printed. https://code.sololearn.com/cHAqka9YOVph
6th Jul 2021, 8:42 AM
David Ashton
David Ashton - avatar
6th Jul 2021, 8:16 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 2
reversed return an iterator of iterable passed as argument in reverse order... to reverse a string, use: s = "".join(reversed("Hello World!")) or better use slicing: s = "Hello World!"[::-1]
6th Jul 2021, 8:16 AM
visph
visph - avatar