In this program, you will learn to convert decimal number to binary using recursive function.
o understand this example, you should have the knowledge of the following Python programming topics:
Decimal number is converted into binary by dividing the number successively by 2 and printing the remainder in reverse order.

Source Code
# Function to print binary number using recursion
def convertToBinary(n):
if n > 1:
convertToBinary(n//2)
print(n % 2,end = '')
# decimal number
dec = 34
convertToBinary(dec)
print()
Output
100010
You can change the variable dec in the above program and run it to test out for other values.
This program works only for whole numbers. It doesn’t work for real numbers having fractional values such as: 25.5, 45.64 and so on. We encourage you to create Python program that converts decimal numbers to binary for all real numbers on your own.
Related posts:
Python String rindex()
Python Set intersection()
Python str()
Python Modules
Python Program to Calculate the Area of a Triangle
Python Program to Check If Two Strings are Anagram
Python Program to Count the Number of Occurrence of a Character in String
Python Machine Learning - Sebastian Raschka
Python Program to Get Line Count of a File
Python ascii()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Add Two Matrices
Python Object Oriented Programming
Python Program to Check Whether a String is Palindrome or Not
Python repr()
Python open()
Python Directory and Files Management
Python String rsplit()
Python List sort()
Python print()
Python Program to Create Pyramid Patterns
Python Program to Get a Substring of a String
Python Set union()
Python Program to Count the Number of Each Vowel
Python Program to Swap Two Variables
Python timestamp to datetime and vice-versa
Python format()
Python Program to Add Two Numbers
Python Program to Find the Square Root
Python bin()
Python Custom Exceptions
Python Set issubset()