Почему при делении целого автоматически получается float?
Например:
a = int(input())
рrint(a/3)
И без разницы, делится нацело или с остатком.
Источник: Stack Overflow на русском
Например:
a = int(input())
рrint(a/3)
И без разницы, делится нацело или с остатком.
Оператор /
в третьем Питоне всегда возвращает вещественное число. Такое правило. Используйте //
для деления нацело.
The / (division) and // (floor division) operators yield the quotient of their arguments. The numeric arguments are first converted to a common type. Division of integers yields a float, while floor division of integers results in an integer; the result is that of mathematical division with the ‘floor’ function applied to the result. Division by zero raises the ZeroDivisionError exception.