- 1

What is these?? % // in python?

14th Jan 2023, 11:24 AM
Bidur Pokhrel
Bidur Pokhrel - avatar
3 Respostas
+ 6
% is modulo operator (remainder after division) // is integer division. See lesson 6 in Python beginner course. https://www.sololearn.com/Course/Python-for-Beginners/?ref=app
14th Jan 2023, 11:27 AM
Tibor Santa
Tibor Santa - avatar
+ 2
% is modulo operator which is used to find the remainder of a division. Eg: 8 % 1 == 0 8 % 2 == 0 8 % 3 == 2 8 % 4 == 0 8 % 5 == 3 8 % 6 == 2 8 % 7 == 1 8 % 8 == 0 8 % 9 == 8 // is the floor division operator. It produces a result that is "floored", when the true divsion operator / produces a float. E.g: 7 / 3 == 2.333333... 7 // 3 == 2 5 / 3 == 1.666666... 5 // 3 == 1 4 / 2 == 2.0 4 // 2 == 2
14th Jan 2023, 11:36 AM
Lochard
Lochard - avatar
+ 1
Hello. Let's say you want to divide one number by another. You do something like: 7 / 2 — the answer will be 3.5 Now, let's say you want that answer to be an integer - you don't want it to have a decimal point. You want to see how many times the division occurs, before there's a remainder and/or decimal point. Therefore you do: 7//2 - the answer will be 3. Because you don't care about the decimal point and/or remainder in here. Now let's say you want to find a remainder of that calculation. You would do something like: 7 % 2 — the answer will be 1. Because you're looking at a remainder of that calculation. // — floor division % — modulo (if that's how you spell it)
14th Jan 2023, 11:38 AM
Lamron
Lamron - avatar