0

I am trying to write a function that takes a string and reverses the words in that string, and then returns the string. I have written this code but when I execute it nothing happens. A blank appears.

def reverse(tex):
new_w = " "
for i in range(0, len(tex)):
    new_w += text[len(tex) - 1 - i]
return new_w
B.Sidhu
  • 1
  • 1

1 Answers1

0
>> name = "pawan"
>> name[::-1]
>> "nawap"

This is better, isn't it?

This is called slicing.

Here's the syntax for slicing:

[ first char to include : first char to exclude : step ]

EDIT: I suggest you take a look at this link.