June 2017
Intermediate to advanced
446 pages
10h 10m
English
Python has the some numeric operators that you would expect; note that the truncating division, (//, also known as floor division) truncates the result to an integer and a floating point and return the integer value. The integer value is returned. The modulo (%) operator returns the remainder value in the division:
>>> 1 + 2 3 >>> 2 - 1 1 >>> 1 * 5 5 >>> 5 / 1 5.0 >>> 5 // 2 2 >>> 5 % 2 1
There are also comparison operators:
>>> a = 1 >>> b = 2 >>> a == b False >>> a > b False >>> a < b True >>> a <= b True
We will also see two of the common membership operators to see whether an object is in a sequence type:
>>> a = 'hello world' >>> 'h' in a True >>> 'z' in a False >>> 'h' not in a False >>> 'z' not in a True
Read now
Unlock full access