[Python-de] Warum liefert // ein float?

Florian Lindner mailinglists at xgm.de
Do Apr 6 03:52:44 EDT 2017


Hallo,

Python 3.6.0 (default, Jan 16 2017, 12:12:55)

>>> x = 3.5
>>> y = 2.5
>>> x // y
1.0

>>> type(x // y)
<class 'float'>

>>> range(x // y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer

Warum liefert // ein float zurück, obwohl das Ergebnis, immer eine eine Ganzzahl ist (in dem Sinne, dass es keine
Nachkommestellen hat)?

Damit ich da raus eine range machen kann, brauche ich wieder int(.), dann kann ich aber gleich auf // verzichten.

Nur mal Interesse halber...

Grüße,
Florian


Mehr Informationen über die Mailingliste python-de