+ 1

Python

how >>>7%(5//2)=1? Can anyone explain it to me?

18th Aug 2018, 5:43 PM
Elizabeth_de_luca
Elizabeth_de_luca - avatar
2 Answers
+ 7
Solve what's in the parenthesis first because of order of precedence: 5 // 2 == 2 The // operator is for floor division. It truncates the result after division (throws away all the decimal places). Then 7 % 2 == 1. The % operator gets the remainder after division. It is called modulus or simply mod operator. P.S.: Use double equal sign "==" when dealing with equations. A single equal sign is the assignment operator, whereas double is for comparison.
18th Aug 2018, 5:49 PM
Eduardo Petry
Eduardo Petry - avatar
+ 1
5//2 == 2 (2.5 without remainder) 7%2 == 1 (Remainder after 7//2)
18th Aug 2018, 5:50 PM
HonFu
HonFu - avatar