division in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

division in python

What is the different between / and % ?

30th Jul 2020, 4:04 PM
Noud Al Mansouri
Noud Al Mansouri - avatar
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
30th Jul 2020, 4:14 PM
Sandra Meyer
Sandra Meyer - avatar
+ 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).
30th Jul 2020, 4:26 PM
E E
E E - avatar