CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2021
    Location
    India
    Posts
    5

    Exclamation Reverse String in Python

    Hi I have recently joined the community here is my first doubt:

    I was reading the python reverse string article and I understood the concept but I got stuck while implementing the same using loop.

    Problem:

    I wanna reverse a random string in a function using a loop,

    I wouldn't use ".join(reversed(string)) or string[::-1] methods here.

    Here is what my code looks like:

    HTML Code:
    def reverse(text):
        while len(text) > 0:
            print text[(len(text)) - 1],
            del(text[(len(text)) - 1]
    I am getting an invalid syntax on on del(text[(len(text)) - 1]

    Any suggestion would be appricated.

    Thank you.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Reverse String in Python

    How about using one of the examples from https://stackoverflow.com/questions/...ring-in-python ?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured