Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

reverse a string or number in python

# Python string/number reverser
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)
Comment

PREVIOUS NEXT
Code Example
Python :: python if column is null then 
Python :: leer fichero de texto con columnas como diccionario python 
Python :: python sepia filter 
Python :: migrate database in django 
Python :: dataframe divided by rowsum 
Python :: how to add user input for a question python 
Python :: stores number in set using input in python 
Python :: get object by name blender python 
Python :: how to connect ip camera to opencv python 
Python :: deletion in a binary search tree 
Python :: copy along additional dimension numpy 
Python :: selenium select svg python3 
Python :: extra import on django 
Python :: typer python 
Python :: wails install 
Python :: how to adda vaslues to data frame 
Python :: rgb to grayscale python 
Python :: python random number between 0 and 1 
Python :: save standard output in variable python 
Python :: 0x80370102 kali linux 
Python :: executing a python script interactively 
Python :: validating credit card numbers 
Python :: query first 5 element in django 
Python :: Run a Flask API from CMD 
Python :: how to make a new key in a dictionary python 
Python :: django delete table data 
Python :: create an array filled with 0 
Python :: return all values in a list python 
Python :: python selenium chrome save session 
Python :: python format decimal list 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =