+ 2

What does % do and how does it work?

3rd Nov 2016, 10:50 PM
fighter_Ethan
5 Answers
+ 2
The % symbol is called "modulo" when used in mathematical reference. It takes both numbers before and after, divides them evenly into whole integers - meaning no decimals - and returns the remaining whole number. Example: 6%4 would return the integer '2'. The reason is that '4' goes into '6' one whole time with '2' left over. 19%5 would return the positive integer '4'. '5' goes into '19' three times (5x3=15, or 15/5=3 depending on how your brain thinks of it best), and there is an integer - '4' - left over due to the fact that '5' cannot go into '4' without being less than a whole number. Modulo will always return a positive whole number or a zero; never a negative one, and never a decimal. In terms of text, it is called a "string operator". Some call it a "placeholder" or a "replacer". You should check it out on Google (:. Happy learning!!
4th Nov 2016, 1:33 AM
phil
phil - avatar
+ 1
The % character is used for getting the remainder of an integer from another integer
3rd Nov 2016, 11:26 PM
Printerm4n
Printerm4n - avatar
0
Example: 10 % 4 = 2
3rd Nov 2016, 11:27 PM
Avery
Avery - avatar
0
fighter_Ethan, python can mean the rest of the division with the modulo operator%. Example: 3% 2 = 1 = 1 5% 2 4% 2 = 0. It can also be used to reference a string that has placed a text output. Example: STRING_1 = "Camelot" STRING_2 = "place" print ( "Let's not go to% s. 'Tis a silly% s."% (STRING_1, STRING_2)). Good studies
3rd Nov 2016, 11:43 PM
Lucas Lacerda
Lucas Lacerda - avatar
0
The % symbol is called "modulo" when used in mathematical reference. It takes both numbers before and after, divides them evenly into whome integers - meaning no decimals - and returns the remaining whole number. Example: 6%4 would return the integer '2'. The reason is that '4' goes into '6' one whole time with '2' left over. 19%5 would return the positive integer '4'. '5' goes into '19' three times (5x3=15, or 15/5=3 depending on how your brain thinks of it best), and there is an integer - '4' - left over due to the fact that '5' cannot go into '4' without being less than a whole number. Modulo will always return a positive whole number; never a negative one, and never a decimal. In terms of text, it is called a "string operator". Some call it a "placeholder" or a "replacer". You should check it out on Google (:. Happy learning!!
4th Nov 2016, 1:32 AM
phil
phil - avatar