BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Convert Decimal to Hexadecimal

Last Updated: June 8, 2018 by Chaitanya Singh | Filed Under: Python Examples

In this tutorial we will see how to convert a decimal value to hexadecimal using a built-in python function.

Program for decimal to hexadecimal conversion

The hex() function converts an integer number to a lowercase hexadecimal string prefixed with “0x”.
0x prefix represent hexadecimal
0b prefix is for binary
0o prefix is for octal

# Program published on https://beginnersbook.com

# Python program to convert decimal to hexadecimal

# Getting the decimal value from user
decimal = int(input("Enter the decimal value for conversion: "))

# converting using built-in function hex()
hex = hex(decimal)

print("The equivalent hexadecimal value is: ", hex)

Output:

Enter the decimal value for conversion: 679
The equivalent hexadecimal value is:  0x2a7

Python decimal to hexadecimal conversion

Reference:
Python docs – built-in functions hex()

Related Python Examples:

1. Python program to convert kilometers to Miles
2. Python program to swap two variables
3. Python program to convert decimal to binary
4. Python program to reverse a String using recursion
5. Python – Getting input from user

Top Related Articles:

  1. Python Program to Check if a Number is Positive Negative or Zero
  2. Python Program to Convert Celsius To Fahrenheit and Vice Versa
  3. Python Program to Convert Kilometers(km) to Miles(mi.)
  4. Python Program to Swap Two Numbers
  5. Python Program to Find Largest Number in a List

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap