当前位置: 代码迷 >> 综合 >> Python integer ranges
  详细解决方案

Python integer ranges

热度:65   发布时间:2024-01-11 02:53:55.0
43 down vote favorite
7

In Python, is there a way to get the largest integer one can use? Is there some pre-defined constant like INT_MAX?

share improve this question
 

1 Answer

active oldest votes
up vote 86 down vote accepted

Python has arbitrary precision integers so there is no true fixed maximum. You're only limited by available memory.

In Python 2, there are two types, int and long. ints use a C type, while longs are arbitrary precision. You can usesys.maxint to find the maximum int. But ints are automatically promoted tolong, so you usually don't need to worry about it:

sys.maxint + 1

works fine and returns a long.

sys.maxint does not even exist in Python 3, since int andlong were unified into a single arbitrary precision int type.

share improve this answer
 
19  
Note that in Python 3 (and Python 2.6 and up)sys.maxsize can be used when you need an arbitrarily-large value. –  mattdm Jan 23 '12 at 19:07




arbitrary

常用词汇
['ɑ?b?tr?ri]    ['ɑ?rb?treri]    
  • adj.任意的;专制的;武断的;霸道的
Adjective:based on or subject to individual discretion or preference or sometimes impulse or caprice;"an arbitrary decision"
"the arbitrary rule of a dictator"
"an arbitrary penalty"
"of arbitrary size and shape"
"an arbitrary choice"
"arbitrary division of the group into halves"

用作形容词 (adj.)
  1. My choice was quite arbitrary.
    我的选择相当随意。
  2. I'm not used to your arbitrary standards.
    我不习惯你们那些随心所欲的标准。
  3. This is an arbitrary decision.
    这是个武断的决定。
adj. (形容词)
  1. arbitrary作“任意的,主观的”解时,主要指不按照客观实际办事; 作“专横的,无理的,独断专行的”解时,主要指无视宪法与法律或别人的利益而是按照自己的意愿任意行使或滥用权力。

precision

常用词汇
[pr?'s??n]    [pr?'s??n]    
  • n.精确;精密度
  • adj.精确的
Noun:the quality of being reproducible in amount or performance;"he handled it with the preciseness of an automaton"
"note the meticulous precision of his measurements"

用作名词 (n.)
  1. The teacher laid emphasis on the precision of the translation from the outset.
    老师从一开始就强调翻译准确性。
  2. Your report lacks precision.
    你的报告不够准确。
  3. Every argument was stated with logical precision.
    每一个论点都阐述得精确严密,符合逻辑。
  4. These instruments are capable of very high precision.
    这些仪器可以达到很高的精密度。
  5. Different time have different concepts on precision or high precision mold.
    对于精密或超精密度模具,不同时期有不同的概念。
查看更多
用作形容词 (adj.)
  1. He spoke with pluperfect precision.
    他用极为精确的话语发言。
  2. Precision measurement is the key to producing interchangeable parts and mass producing goods.
    精确的测量是生产互换零件和批量产品的关键。




  相关解决方案