Answers for "how to flip a string in python"

29

how to reverse a string in python

# in order to make a string reversed in python 
# you have to use the slicing as following

string = "racecar"
print(string[::-1])
Posted by: Guest on November-26-2020
0

how to flip a string python

txt = "Hello World"[::-1]
print(txt)#dlroW olleH
Posted by: Guest on May-21-2021
-1

reverse a string in python

# Python string/number reverser
# Kinda too much code, so don't use this, use the other examples under this answer.
example_number = 12143
example_string = "Hello there"

def reverse(thing): 
    thing = str(thing) # convert it to a string, just in case it was a number
    list_of_chars = [char for char in thing]
    reversed_list_of_chars = []
    x = -1
    
    for char in list_of_chars:
      reversed_list_of_chars.append(list_of_chars[x])
      x += -1
    
    reversed_thing = ''.join(reversed_list_of_chars)
    
    return reversed_thing
    # Or alternatively do:
    print(reversed_thing)

# Run it by doing this
reverse(example_number)
reverse(example_string)
Posted by: Guest on July-23-2020

Python Answers by Framework

Browse Popular Code Answers by Language