+ 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
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
+ 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())
+ 3
+ 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.