0

How does reverse function works because I tried:. x=str(input ()) x=x.reverse() print(x). And that didn't work

29th Feb 2020, 4:24 AM
Taraash Mittal
Taraash Mittal - avatar
5 odpowiedzi
+ 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().
29th Feb 2020, 8:00 AM
David Ashton
David Ashton - avatar
+ 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)
29th Feb 2020, 4:49 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 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
29th Feb 2020, 4:38 AM
Gordon
Gordon - avatar
+ 4
You can reverce a string by using reverced(). it creates a reversed object. inp = reversed(input('name: ')) print(''.join(inp))
29th Feb 2020, 6:50 AM
Lothar
Lothar - avatar
0
Thanks, but can you please give an example using the reverse method?
29th Feb 2020, 4:41 AM
Taraash Mittal
Taraash Mittal - avatar