Conversion of various underlying types in Python, binary, octal, decimal, hex

Source: Internet
Author: User
Tags ord

All types in Python exist as objects.

There is no char type in Python, only a string type, which makes it very inconvenient for us to convert the char type to integer, but Python already provides built-in functions for these transformations.

In Python, in addition to Integer, the other binary can only be represented by a string.

1 int ()

Binary, octal, 16-binary can be converted to decimal integer

>>> int (' 1111 ', 2) 15>>> int (' F ', +) 15>>> int (' 17 ', 8) 15

2 Chr ()

Convert an integral type to a character

>>> chr ' Z '

3 Ord ()

Convert a character to an integral type

>>> Ord (' Z ') 90

4 Hex ()

Convert decimal to hexadecimal

>>> Hex (255) ' 0xFF '

5 Oct ()

Convert Decimal to Octal

>>> Oct (255) ' 0377 '

6 bin ()

Convert decimal into binary

>>> Bin (255) ' 0b11111111 '


Conversion of various underlying types in Python, binary, octal, decimal, hex

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.