+ 2
what is the meaning of the "%" symbol in python
8 ответов
+ 6
Please read the comments down below the lesson.
+ 2
Julius
It is a mod operator
It gives you the remainder
5%2 = 1
4%2 = 0
16%7 = 2
...... Etc....
+ 1
Used for modulo division to get the remainder.
+ 1
Julius
% symbol used to get remainder
Ex 99%50=49
Here 49 is in RHS because 49 will be the remainder in this case
0
Depends on the context. If you're using the operator with Integral Operands (numbers, integers or float-point), then it behaves as the Modulo Operator, returning the Remaining from the division between the Operands:
>>> 3 % 2
>>> 1 # 3 // 2 == 1
Another use for the percentage symbol is when formating strings:
>>> '%s is %d years old' % ('Erick', 22)
>>> 'Erick is 22 years old'
Inside the string we place it to indicate what should appear in the string in that position, and after the template str we use it to indicate what values should be present in the final str.
In the example, "%d" in the template str means that in that position and str should appear; and "%d" means that in that position should appear an number.
0
Using the "%" operator you can get the remainder.
For ex:-
10 % 3 = 1
5 % 3 = 2
20 % 5 = 0
Hope you got it 👍
- 1
returns the remainder of a division ! for example 2%2=0 because 2 is a factor of 2 and when we divide it there is no remainder similar to 8%2=0 because 8 gets divides by 2 , 4 equal times ! but 5%3= 2 because 3 will go into 5 one time and what gets returned is the remainder which is 5-3=2 ! simalar to 8%3= 2 3 goes into 8 two times so 8-6=2 which is considered the remainder returned by”%”