![]() ![]() Let's look at a couple of examples: > 10 // 3 In Python, the modulo operator simply yields the remainder: > 10 % 3įloor division is also used to carry out Euclidean division, but unlike the modulo operator, floor division yields the quotient, not the remainder. To give you another example, 11 / 3 gives us a quotient of 3 and a remainder of 2. ![]() The amount left over after the division is called the remainder, which in this case is 1. We care about the whole number result of the division (in this case 3), which is called the quotient. In Euclidean division, we don't care about numbers after the decimal point. In what we might think of as "standard division" the result of 10 / 3 is 3.333 recurring, or 3 and a third. When performing Euclidean division, you start with a dividend (a number you want to divide), and a divisor (the number you want to divide the dividend by). You almost certainly learnt about Euclidean division in school, even if you didn't know what it was called. The modulo operator is used to carry out Euclidean division. What do modulo and floor division do? Modulo In this post I'm going to talk about the modulo ( %) and floor division ( //) operators, and some common pitfalls associated with them. In addition to the common operators for addition, subtraction, multiplication, and division, the Python standard library includes some arithmetic operators you may be less familiar with. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |