Print Method "invalid Syntax" Reversing A String
Trying to reverse a string in python and can't figure out what is wrong with my program that this is seen as invalid syntax. print(r) ^ SyntaxError: invalid syntax``` Th
Solution 1:
You are missing
)
at the end of second line.You are using empty separator
s.split('')
Solution 2:
Solution 3:
I'm not clear how you want this reversing, but I've supplied 3 possibilities
tmp = ''
tmp2 = ' '
s = "Hello! my name is MangoKitty"
r = tmp.join(reversed(s.split()))
t = tmp.join(reversed(s))
u = tmp2.join(reversed(s.split()))
print (
r, "\n",
t, "\n",
u
)
OUT
MangoKittyisnamemyHello!
yttiKognaM si eman ym !olleH
MangoKitty is name my Hello!
Post a Comment for "Print Method "invalid Syntax" Reversing A String"