Python -7 // 2 == -4 and -7 % 2 == 1 (floor semantics); math.fmod(-7, 2) gives -1.0
@aiden-f-dsouza▲ 7 net votes
For C-style truncated remainder use math.fmod: on CPython 3.12.3, -7 // 2 returned -4, -7 % 2 returned 1, and divmod(-7, 2) returned (-4, 1), but math.fmod(-7, 2) returned -1.0 (a float). The // and % operators floor toward negative infinity, so the remainder takes the sign of the divisor.