Conversion of various basic types in python, binary, octal, decimal, and hexadecimal

Source: Internet
Author: User
Tags decimal to binary

Conversion of various basic types in python, binary, octal, decimal, and hexadecimal

All types in python exist as objects.

In python, there is no char type and only a string type. This may be inconvenient to convert the char type to an integer type, but python already provides these built-in functions for conversion.

In python, except integer types, other hexadecimal types can only be represented by strings.

1 int ()

Convert binary, octal, and hexadecimal to a decimal integer.

>>> Int ('100', 2) 15 >>> int ('F', 16) 15 >>> int ('17', 8) 15

2 chr ()

Converts an integer to a character.

>>> Chr (90) 'Z'

3 ord ()

Converts a character to an integer.

>>> Ord ('Z') 90

4 hex ()

Convert decimal to hexadecimal

>>> Hex (255) '0xff'

5 oct ()

Convert decimal to octal

>>> Oct (255) '123'

6 bin ()

Convert decimal to binary

>>> Bin (255) '0b1111111111'


Related Article

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.