+ 2

Какая разница между функциями // и %?

16th Jun 2017, 8:32 PM
Kanal Ximkera
Kanal Ximkera - avatar
4 ответов
+ 4
// is a floor division - it rounds down the division result to the nearest lower integer % returns the remainder of the division 17 // 4 = 4 (17/4=4.25, rounded down is 4) 17 % 4 = 1 (1 is a remainder of the division above)
16th Jun 2017, 8:43 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
If you want to do both, divmod(a,b) returns (a//b, a%b)
16th Jun 2017, 10:04 PM
David Ashton
David Ashton - avatar