Maximum and Minimum values for ints

前端 未结 9 2015
北荒
北荒 2020-11-22 06:36

I am looking for minimum and maximum values for integers in python. For eg., in Java, we have Integer.MIN_VALUE and Integer.MAX_VALUE. Is there som

9条回答
  •  日久生厌
    2020-11-22 07:15

    If you want the max for array or list indices (equivalent to size_t in C/C++), you can use numpy:

    np.iinfo(np.intp).max
    

    This is same as sys.maxsize however advantage is that you don't need import sys just for this.

    If you want max for native int on the machine:

    np.iinfo(np.intc).max
    

    You can look at other available types in doc.

    For floats you can also use sys.float_info.max.

提交回复
热议问题