Elementary string-formatting

John Machin sjmachin at lexicon.net
Sun Jan 13 10:54:33 CET 2008


On Jan 13, 8:43 pm, Odysseus <odysseus1479... at yahoo-dot.ca> wrote:
> In article
> <e6f9c0c3-d248-46ae-af0f-fbb8ab279... at v46g2000hsv.googlegroups.com>,
>  Roberto Bonvallet <rbonv... at gmail.com> wrote:
>
> > Put this at the beginning of your program:
>
> >     from __future__ import division
>
> > This forces all divisions to yield floating points values:
>
> Thanks for the tip. May I assume the div operator will still behave as
> usual?

div operator? The integer division operator is //

>>> from __future__ import division
>>> 1 / 3
0.33333333333333331
>>> 1 // 3
0
>>> 22 / 7
3.1428571428571428
>>> 22 // 7
3
>>> 22 div 7
  File "<stdin>", line 1
    22 div 7
         ^
SyntaxError: invalid syntax
>>>



More information about the Python-list mailing list