[Tutor] doubt in a program

Jan Erik Moström lists at mostrom.pp.se
Mon Jan 29 08:25:04 EST 2018


On 29 Jan 2018, at 7:42, vinod bhaskaran wrote:

> As the new character is adding the char in the new string but how is 
> it
> getting reversed without any line giving the char number to be 
> traversed in
> reverse order.

You don't need that, think about this example

newstring = ''
oldstring = "Newton"

now you go through each char in oldstring, so you get first N which you 
add to newstring and you get

newstring = 'N'

next char is 'e' and then you do 'e' + 'N' and get 'eN'

newstring = 'eN'

next char the same way

newstring = 'weN'

etc

until you get 'notweN'

Remember that the for-loop will step through each char in oldstring so 
when you come to the end the loop will stop.

= jem


More information about the Tutor mailing list