1

In Java or C++ we have a data type called unsigned double or unsigned int etc. How does python differentiate between them? I am asking this because in some cases we known that the numbers are not going to be negative so its better to use unsigned. The ranges are different for both type of data types.

I have already gone through a similar question but it addresses the general idea.

2 Answers 2

7

It doesn't. There is no such distinction in the Python builtin types, because there are no unsigned numeric types.

Sign up to request clarification or add additional context in comments.

4 Comments

Then isn;'t it a drawback since unsigned integer has a bigger range on the positive side.
@AnimeshPandey: Of course. But speed isn't the primary reason for using Python in the first place.
@AnimeshPandey: It depends on what you consider a drawback. Python integers aren't just primitive floating-point types; they're Python objects. So you can make a Python int (positive or negative) as big as you want. The drawback, if any, is that this flexibility makes operations of the numbers slower, but the tradeoff is you can almost completely forget about the kinds of nitty-gritty details that you're asking about in your question.
Hmmm. This makes sense. Thanks for this.
1

There is no unsigned/signed distinction in python. However, if you absolutely must have unsigned integers you can always import types from the ctypes module.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.