0
division in python
What is the different between / and % ?
2 Answers
+ 2
a / b -> result of division
a % b -> result modulo of division
You can use the Q&A button on the upper right corner of a lesson to directly find discussions related to this topic:
https://www.sololearn.com/Discuss/1505951/?ref=app
+ 2
the division operator (/) takes two numbers, x/y and performs a division operation.
e.g.: 10/3 = 3 or 10.0/3.0 = 3.333... etc.
the modulus operator (%) takes 2 numbers and performs a modulo operation; in other words it takes x, divides it by y, and returns the remainder.
e.g.: 10%3 would evaluate as 1 (imagine 10/3 = 3 + remainder 1)
the similarities are that they are both binary operators (2 variables for input) and that they both are related to division in a sense. they have completely different use cases.
i personally use "%" to create the illusion of "looping" objects (like a background) or creating a tilemap. it's also used in the generation of 3d fractals if i'm aware. and there's way more to it than just this.
on the other hand i use the "/" operator when dealing with literal ratios or perspective/zooming (on a logarithmic scale).