Tuesday, June 28, 2011

Re: Curious int/float/division/math 'gotcha' in py (discussion)

On 2011-06-28, at 15:39 , Tom Evans wrote:

> On Tue, Jun 28, 2011 at 2:36 PM, Masklinn <masklinn@masklinn.net> wrote:
>> On 2011-06-28, at 15:31 , Tom Evans wrote:
>>>
>>> Bit OT, but I'll bite (doesn't really relate to Django). Dividing two
>>> ints ALWAYS returns an int.
>> Unless you've switched to Python 3, or imported division from __future__ in which case true division is the default, and integer division is bumped to '//'.
>>
>>> Calling math.ceil() ALWAYS returns a
>>> float. I think you were expecting that python would automagically
>>> store the remainder somewhere so that math.ceil() has something to
>>> operate on. It doesn't do that!
>> Or he was expecting that Python uses true division always (a default the core team seems to agree with since they changed it in 3.0)
>>
>
> Seeing as this is django-users@, and not c.l.python, this applies:
>
> https://docs.djangoproject.com/en/dev/faq/install/#can-i-use-django-with-python-3
No, it does not.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment