0
How does reverse function works because I tried:. x=str(input ()) x=x.reverse() print(x). And that didn't work
5 Answers
+ 10
You never need to use str(input()) because input() always produces a string. You need to use int(input()) and float(input()) to convert your input into an integer or a float, but str(input()) is redundant - just use input().
+ 6
Taraash Mittal ,
#example of list's reverse method.
l = [1,2,3,4,5,6]
res = l.reverse() #reverses list in place , returns `None`
print(l , res)
+ 4
In Python, reverse() is a list method, not a string method.
Use list slicing with a negative step instead.
https://code.sololearn.com/cwGzxHxO60k1/?ref=app
+ 4
You can reverce a string by using reverced(). it creates a reversed object.
inp = reversed(input('name: '))
print(''.join(inp))
0
Thanks, but can you please give an example using the reverse method?