- reverse() and reversed() both are python in-buid function which are used to reverse the content of the list.
- reverse() is only applicable on list.
- while reversed() is also work on the string data type.
print("Reverse list is",l)
print("Again reverse by reversed() function",*reversed(l))
print("String in reverse order",*reversed(s))
List is [1, 2, 3]
Reverse list is [3, 2, 1]
Again reverse by reversed() function 1 2 3
string is Mytext
String in reverse order t x e t y M
-In this program, we take a list and reverse the item in the list by both reverse()
and reversed() function.
- and then we reverse the string by using the reversed() function.