what is the meaning of the "%" symbol in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

what is the meaning of the "%" symbol in python

14th Dec 2020, 8:52 AM
Julius
Julius  - avatar
8 Answers
+ 6
Please read the comments down below the lesson.
14th Dec 2020, 8:55 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Julius It is a mod operator It gives you the remainder 5%2 = 1 4%2 = 0 16%7 = 2 ...... Etc....
14th Dec 2020, 11:21 AM
Krish
Krish - avatar
+ 1
Used for modulo division to get the remainder.
15th Dec 2020, 12:03 AM
Sonic
Sonic - avatar
+ 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
15th Dec 2020, 12:04 PM
คгשเภ๔ кย๓คг
คгשเภ๔ кย๓คг - avatar
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.
16th Dec 2020, 2:55 AM
Erick Ruh Cardozo
Erick Ruh Cardozo - avatar
0
Using the "%" operator you can get the remainder. For ex:- 10 % 3 = 1 5 % 3 = 2 20 % 5 = 0 Hope you got it 👍
16th Dec 2020, 4:46 AM
‎Keshav
‎Keshav - avatar
- 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”%”
15th Dec 2020, 10:16 AM
Romina