August 2018
Intermediate to advanced
466 pages
10h 23m
English
Python has 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 returns the integer value. The modulo (%) operator returns the remainder value in the division:
>>> 1 + 23>>> 2 - 11>>> 1 * 55>>> 5 / 15.0>>> 5 // 22>>> 5 % 21
There are also comparison operators. Note the double equals sign for comparison and a single equals sign for variable assignment:
>>> a = 1>>> b = 2>>> a == bFalse>>> a > bFalse>>> a < bTrue>>> a <= bTrue
We can also use two of the common membership operators to see whether an object is in a sequence type:
>>> a = 'hello world'>>> 'h' in aTrue>>> 'z' in aFalse>>> 'h' not in aFalse ...
Read now
Unlock full access