Home > Net >  How to specify int8/int16 in Python
How to specify int8/int16 in Python

Time:12-28

Int type is int32 or int64 in default in Python3.
How can we specify int8/int16 when declaring variable?
It is not possible in Python?
It is waste of memory if the int object is small and int8/int16 cannot be specified.

CodePudding user response:

Afaik python chooses the type according to the size of the number and there is no way of specifying which type of int you want python to use. If you are concerned about the waste of memory, python may not be the correct choice in the first place.

CodePudding user response:

Python doesn't have any built-in support for 8 or 16-bit integers. NumPy, on the other hand, does support the sizes you're looking for:

import numpy as np
print(np.uint8(22))
  • Related