[Tutor] meaning of % in: if n % x == 0:
Alan Gauld
alan.gauld at btinternet.com
Thu Sep 1 01:32:46 CEST 2011
On 31/08/11 20:35, Lisi wrote:
> ?? If either n or x or both were 0, and % were the same thing as *, the
> statement would be true, but from the context I don't think that % does mean
> the same as *, because * appears very soon after in the same fragment of
> code.
It's the remainder operator:
IF N MOD X = 0
in BASIC
It's explained in the Simple Sequences topic of my tutorial and
mentioned again in the Raw Materials topic under integers.
The use of % as the operator goes back to C. Many of Python's
operators are just inherited directly from C.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list