Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to reverse a number in python

num = 123456
print(str(num)[::-1])
Comment

reverse a 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 :: how to save data to text file python 
Python :: scrape with beautiful soup 
Python :: none address in python 
Python :: streamlit button to load a file 
Python :: browser pop up yes no selenium python 
Python :: splittext py 
Python :: django admin order by 
Python :: how to change angle of 3d plot python 
Python :: df order by 
Python :: max int value in python 
Python :: python list group by count 
Python :: add element to heap python 
Python :: remove nan particular column pandas 
Python :: turn off grid in matplotlib 3d 
Python :: native bold text 
Python :: resize multiple images to same size python 
Python :: pytest installation windows 
Python :: python get weather temperature 
Python :: text to binary python 
Python :: python program to find fibonacci series using function recursion loop 
Python :: add empty column to dataframe pandas 
Python :: all permutations python 
Python :: python text underline 
Python :: invoice parsing ocr python 
Python :: print list vertically in python with loop 
Python :: python sum attribute in list 
Python :: how to add headings to data in pandas 
Python :: get index of element in numpy array python 
Python :: rotatable list python 
Python :: How to convert text into audio file in python? 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =