The Modulo Operation (%) With Negative Numbers in Python

Have you ever wondered how it works?

Gonzalo Ferreiro Volpi
Better Programming
Published in
4 min readSep 28, 2020

--

Using the modulo operator.
Photo by the author.

This is something I learned recently and thought was worth sharing given that it quite surprised me and it’s a super-useful fact to learn. How does Python handle the modulo operation with negative numbers? So, let’s keep it short and sweet and get straight to it.

“The % symbol in…

--

--

ELI5 DATA: Explain Like I’m 5 | Just a guy trying to make data simpler | Data Scientist @ Ravelin | Fancy joining my mailing list? 👉🏻http://eepurl.com/gA_rkj