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

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

Leave a Reply Cancel reply

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

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap