What are the design issues driving Python to not support built in unsigned types?
I know that in Python an int
is an abstraction of an integer value, but why can it not represent the abstraction fixed-byte-size integer?
What are the design issues driving Python to not support built in unsigned types?
I know that in Python an int
is an abstraction of an integer value, but why can it not represent the abstraction fixed-byte-size integer?
In a non-Python like language like C, the unsigned type is very useful if you want control over the exact range and wrapping of your numbers.
In Python, as Alex Hall mentioned in the comment, ints have unlimited precision. Therefore the distinction between signed and unsigned does not really have any meaning.
If you are looking to optimize performance of your code and are willing to give up the flexibility and power of Python, you could use Cython and annotate specific variables as "unsigned int". Have a look at http://docs.cython.org/src/userguide/language_basics.html.
For the same reason that PHP or Java doesn't. From here, about Java:
Gosling: For me as a language designer, which I don't really count myself as these days, what "simple" really ended up meaning was could I expect J. Random Developer to hold the spec in his head. That definition says that, for instance, Java isn't -- and in fact a lot of these languages end up with a lot of corner cases, things that nobody really understands. Quiz any C developer about unsigned, and pretty soon you discover that almost no C developers actually understand what goes on with unsigned, what unsigned arithmetic is. Things like that made C complex. The language part of Java is, I think, pretty simple. The libraries you have to look up.
So it's really about simplicity.
If you feel like you really need this feature, you can always use ctypes
.