unsigned integer?
Duncan Booth
duncan.booth at invalid.invalid
Sat Mar 10 13:34:38 EST 2007
"Dan Bishop" <danb_83 at yahoo.com> wrote:
> On Mar 10, 11:50 am, Duncan Booth <duncan.bo... at invalid.invalid>
> wrote:
>> "Jack" <nos... at invalid.com> wrote:
>> > This is a naive question:
>>
>> > "%u" % -3
>>
>> > I expect it to print 3. But it still print -3.
>>
>> Internally it uses the C runtime to format the number, but if the
>> number you ask it to print unsigned is negative it uses %d instead of
>> %u. I have no idea if it is actually possibly to get a different
>> output for %d versus %u.
>
> %u used to be different from %d, but it changed because of the int/
> long unification in Python 2.4.
>
Yes, I guessed that was it.
The implementation is identical when the value is negative but still
different when the integer is non-negative which is why I questioned
whether it was actually possible to get different output. If not perhaps
both the implementation and the documentation should be simplified.
More information about the Python-list
mailing list