# Name conflicts from operator import add, mul def square(x): return mul(x, x) def square(mul): return mul(mul, mul) def square(square): return mul(square, square) # Operators 2 + 3 add(2, 3) 2 + 3 * 4 + 5 add(add(2, mul(3, 4)) , 5) (2 + 3) * (4 + 5) mul(add(2, 3), add(4, 5)) # Multiple return values def divide_exact(n, d): return n // d, n % d quotient, remainder = divide_exact(2012, 10) # Dostrings, doctests, & default arguments from operator import floordiv, mod def divide_exact(n, d): """Return the quotient and remainder of dividing N by D. >>> quotient, remainder = divide_exact(2012, 10) >>> quotient 201 >>> remainder 2 """ return floordiv(n, d), mod(n, d) # Boolean values and operators 4 < 2 5 >= 5 True and False True or False not False # Conditional expressions def absolute_value(x): """Return the absolute value of X. >>> absolute_value(-3) 3 """ if x < 0: return -x elif x == 0: return 0 else: return x # Summation via while i, total = 0, 0 while i < 3: i = i + 1 total = total + i total