anyone remember `from __future__ import division`

· · Web · 1 · 3 · 1

@octopus why was division in the future

(asking as someone who's pretty sure that's Python but knows nothing else about it)

@WizardOfDocs python originally did integer division by default, so

13 / 5 = 2 (with remainder 13 % 5 = 3)

nobody liked this so it was decided that when they got around to python 3, division would produce floats when it made sense, and if you needed integer division for some reason you should use `//`

13 / 5 = 2.6
13 // 5 = 2

you could opt into the new behavior by importing it from the future! (from long before 3.0 was released)

@octopus @WizardOfDocs in general "from __future__" is Python's way of opting in to language changes that are going to be made in future releases. very helpful for eg. the Python 2->3 migration

There are some more details here

Sign in to participate in the conversation

cybrespace: the social hub of the information superhighway jack in to the mastodon fediverse today and surf the dataflow through our cybrepunk, slightly glitchy web portal support us on patreon or liberapay!