# Python Program to reverse a number using recursion

In this program, you will learn how to reverse a number using recursion in Python.

``````123 => 321

4561 => 1654``````

## Example: How to reverse a number using recursion in Python

``````rev = 0

def reverse(n):
global rev
if n > 0:
r = n % 10
rev = rev * 10 + r
reverse(int(n / 10))
return rev

n = int(input("Enter a number:"))

num = reverse(n)
print("After reverse number is:", num)``````

#### Output:

``````Enter a number:123
After reverse number is: 321``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.51743466,"math_prob":0.99128956,"size":418,"snap":"2021-04-2021-17","text_gpt3_token_len":124,"char_repetition_ratio":0.17874396,"word_repetition_ratio":0.077922076,"special_character_ratio":0.36124402,"punctuation_ratio":0.125,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9981087,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-19T13:26:55Z\",\"WARC-Record-ID\":\"<urn:uuid:887d696d-7135-4418-8799-f083576b71df>\",\"Content-Length\":\"35438\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bd97c350-1607-4bc1-917a-934459d4851a>\",\"WARC-Concurrent-To\":\"<urn:uuid:78970f73-e4f0-4986-b101-5996542985fc>\",\"WARC-IP-Address\":\"104.21.39.92\",\"WARC-Target-URI\":\"https://xiith.com/python-program-to-reverse-a-number-using-recursion/\",\"WARC-Payload-Digest\":\"sha1:B6XHPV6TTSJBJGY5YQOQ4CLU3WPXXHLE\",\"WARC-Block-Digest\":\"sha1:M5E6T3QMJZ3SCYFZ6SMGSV266LYMNJSP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038879374.66_warc_CC-MAIN-20210419111510-20210419141510-00331.warc.gz\"}"}