Analysis of syntax and conversion methods for different operating systems in Python

Source: Internet
Author: User

Analysis of syntax and conversion methods for different operating systems in Python

This article describes the syntax and conversion methods of different hexadecimal formats in Python. We will share this with you for your reference. The details are as follows:

Different hexadecimal writing methods

① Octal (Octal) 0o377
② Hex 0xFF
③ Binary 0b111111

Conversion between different hexadecimal values

Python provides three built-in functions that can be used for conversion between different operating systems.

>>> Oct (255), hex (255), bin (255) ('0o377', '0xff ', '0b1111111111 ')

You can also use the int function to convert a string to a value.

>>> Int ('000000'), int ('0xff ', 16) (255)

In addition, you can also use eval, which is similar to the int function, but its parameter is python code.

>>> Eval ('000000'), eval ('0xff ') (255)

Of course, you can also format the Output Using strings.

>>> '{0: 0}, {1: x}, {2: B }'. format (255,255,255) '2014, ff, 255 '>>>' % o, % x, % x' % (11111111) '2014, ff, ff'

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.