Почему при делении целого автоматически получается float?
Например:
a = int(input())
рrint(a/3)
И без разницы, делится нацело или с остатком.
Ответы (1 шт):
Автор решения: Stanislav Volodarskiy
→ Ссылка
Оператор / в третьем Питоне всегда возвращает вещественное число. Такое правило. Используйте // для деления нацело.
6.7. Binary arithmetic operations
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.