Python standard library: built-in functions hex (x) and pythonhex

Source: Internet
Author: User

Python standard library: built-in functions hex (x) and pythonhex

This function is used to convert a hexadecimal string representation of an integer object, such as the 0x format. If the object is not an integer, define a method ___ index _ () to return an integer. If you want to convert the result of this function to the integer type, you must use the int () function and the base number is 16. In addition, if the floating point number is converted to hexadecimal notation, float. hex () is used for conversion, rather than this function.

Example:

# Hex () print (hex (20) print (hex (128) print (hex (0x55) print (hex (-127 ))

The output result is as follows:

0x14

0x80

0x55

-0x7f


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.