+ 1
I am just get into coding. I want to ask a question about what is % in python. I always get confused with this sign
2 Answers
+ 4
The "%" symbol is also used in formatting output for print. It is used there as a placeholder, e.g. in conjunction with format specifiers.
from datetime import datetime
print('{:%Y-%m-%d %H:%M}'.format(datetime(2001, 2, 3, 4, 5)))
# output: 2001-02-03 04:05
print('%d %f' % (1, 2))
# output: 1 2.000000
+ 3
It is modulo operator which devides two numbers and returns it's remainder.
For example:-
5%2 = 1
14%7 = 0