Python's numeric type

Source: Internet
Author: User

> Python contains 3 types of numeric values: integers, floating-point numbers, and complex numbers.

Integer

Integers are represented in Python in four ways, binary, octal, decimal, hexadecimal. Humans use decimal for the representation of numeric values, so the final output of the Python interpreter is decimal regardless of the method used.

Integer constants

Binary starts with 0b or 0 B followed by a value:

in [+]: 0b10out[]: 2 in[]: 0b11out[56]: 3

Octal starts with 0o or 0O followed by a value:

In []: 0o17out[]:[Max]: 0o20out[61]: 16

Decimal is the default constant and can be entered directly into the value:

in [+]:out[[]: Ten in[]:out[63]: 20

Hexadecimal starts with 0x or 0X followed by a value:

in [+]: 0x18out[]:[+]: 0x24out[65]: 36
constructor function

In addition to creating integers directly using constants, you can also use the constructor int () to create integers, using integer constants or decimal numeric strings in int:

In [the]: Int (0B11) out[[3]: Int (0B11) out[]: 3 in[]: Int (0B11) out[ [3]:int (0o11) out[]: 9 in[]: Int (one) out[): one in[74] : Int (0x21) out[":[+]: Int ('1') out[75]: 1

Python's numeric type

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.