Python Tip: Python3 represents the maximum integer value and the floating-point value __python

Source: Internet
Author: User
first, the introduction

This is what I was inspired to learn from the 28th page of the book "Python Algorithms 2nd":

For intergral weights, your could use Sys.maxint, even though it ' s not guaranteed to is the greatest possbile value (long INTs can be longer).

We say less, direct test code:

Import sys
print (sys.maxint)

We look forward to thinking that we can output the largest integer value, and found the error:

Traceback (most recent call last):
File "", Line 1, in
Attributeerror:module ' sys ' has no attribute ' maxint '

So, what is this for? Second, explore

The Chinese community has little to do with this issue, so I found a description of the foreign friends on StackOverflow:

The Sys.maxint constant was removed, since there are no longer a limit to the value of integers. However, sys.maxsize can be used as a integer larger than any pratical list or string index. It conforms to the implementation ' natural ' integer size and are typically the same as Sys.maxint in previous releases on The same platform (assuming the same build options).

That is, in a new release, Sys.maxint has been removed because there is no limit to integer values. However, the standard provides a sys.maxsize to represent a larger integer value than any of our actual work can represent. This value is exactly the same as the original sys.maxint.

Well, let's test this:

Import sys
print (sys.maxsize)

On my machine, the results of the operation are:

9223372036854775807

In addition, to express the largest floating-point value, you can:

Print (float (' inf '))

Output of the expression above:

Inf

Used to express infinitely large floating-point values. Third, summary

is actually two words:

Sys.maxsize

Float (' inf ')

Easy to remember, easy to use:)

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.