Sujet : Re: "undefined behavior"?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 15. Jun 2024, 02:39:50
Autres entêtes
Organisation : None to speak of
Message-ID : <87r0cz3rx5.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
DFS <
nospam@dfs.com> writes:
[...]
During conversion, I got a Python error I don't remember seeing in the past:
>
"TypeError: list indices must be integers or slices, not float"
>
because division returns a float, and some of the array addressing was
like this: nums[i/2].
[...]
C's "/" operator yields a result with the type of the operands (after
promotion to a common type).
Python's "/" operator yields a floating-point result. For C-style
integer division, Python uses "//". (Python 2 is more C-like.)
See
https://docs.python.org/3/ or comp.lang.python, which is reasonably
active.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */