+ 3

How i can solve this error?

def reverse(x): x = x.split() x = x.reverse() x =''.join(x) reverse(input()) When trying to make a string in reverse order, an error occurs

7th May 2020, 10:22 AM
_nrkvv_
_nrkvv_ - avatar
5 Réponses
+ 3
x.reverse() which is a list method returns none ,so you are storing None in x Simply do x.reverse() Instead of x=x.reverse() also this applies to if you are talking about reversing words in a statement otherwise as Rithea Sreng said you can't do like that if you want to reverse words in a word
7th May 2020, 10:32 AM
Abhay
Abhay - avatar
+ 3
There is no need to split the input, as this creates a list. Try something like this: ( this could be shortened, but in case of understanding this is OK. What i recommend to you is to go learning the basics of python with the tutorials provided from sololearn.) def reverse_(x): x = list(reversed(x)) x =''.join(x) print(x) reverse_(input())
7th May 2020, 10:34 AM
Lothar
Lothar - avatar
+ 3
Rithea Sreng CarrieForle Abhay Thank you very much, I was able to solve it😊
7th May 2020, 10:36 AM
_nrkvv_
_nrkvv_ - avatar
+ 1
x.reverse() returns None and you assign it to x. Change x = x.reverse() to x.reverse(). Also, the code didn't print the result.
7th May 2020, 10:32 AM
你知道規則,我也是
你知道規則,我也是 - avatar