[N00B] What's %?
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Feb 10 12:57:50 EST 2005
administrata a écrit :
> Hi! it's been about a week learning python!
> I've read 'python programming for the absolute begginer'
> I don't understand about % like...
>
> 107 % 4 = 3
> 7 % 3 = 1
it's the modulo operator (if you don't remember, the modulo is the
remaining of the integer division, ie 5 % 2 = 1)
One of the most commun use is to test wether a number is odd or even:
any_even_number % 2 == 0
any_odd_number % 2 == 1
Note that the % operator is also used for string formating, ie:
"%d modulo %d = %d" % (5, 2, 1)
=> "5 modulo 2 = 1"
> Please help me...
HTH
Bruno
More information about the Python-list
mailing list