Home > Backend Development > Python Tutorial > What is the maximum possible value of an integer in Python? (code example)

What is the maximum possible value of an integer in Python? (code example)

藏色散人
Release: 2019-03-16 14:32:27
Original
8621 people have browsed it

What is the maximum possible value of an integer in Python? (code example)

In Python, large values ​​can be stored, such as the following Python sample program:

x = 10000000000000000000000000000000000000000000; 
x = x + 1
print (x)
Copy after login

Output:

10000000000000000000000000000000000000000001
Copy after login

In Python, integers The value is not limited by the number of bits and can be extended to the limit of available memory. Therefore, we never need any special arrangement to store large numbers (imagine doing the above arithmetic in C/C++).

In Python 3, for all types of integers, there is only one type "int". In Python 2.7. There are two different types "int" (32 bit) and "long int" which is the same as Python 3.x's "int", i.e. can store arbitrarily large numbers.

#Python 2.7中有两种类型:int和long int
#在Python 3中只有一种类型:int
  
x = 10
print(type(x)) 
  
x = 10000000000000000000000000000000000000000000
print(type(x))
Copy after login

Output in Python 2.7:

<type &#39;int&#39;>
<type &#39;long&#39;>
Copy after login

Output in Python 3:

<type &#39;int&#39;>
<type &#39;int&#39;>
Copy after login

This article is an introduction to the maximum possible value of an integer in Python. Hope it helps those in need! (Related recommendations: "Python Tutorial")

The above is the detailed content of What is the maximum possible value of an integer in Python? (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template