Learning Python: Chapter 13

  • while and for loops may have an else block that is executed if the loop terminates naturally, that is, not by a break statement.
  • There is a no-op statement called pass.
  • Assignments to variables do not return the assigned value; they are statements, not expressions.
  • You can build your own iterables by implementing a next method that raises a StopIteration exception when reaching whatever is considered to be the end.
  • You can check if any or all elements of an iterable evaluate to True with with any(it) and all(it).
  • You can use zip to iterate over multiple iterables in a single loop.
  • zip truncates to the length of the shortest participating sequence, whereas map pads with None to match the length of the longst one.
  • The built-in enumerate provides both elements and their offsets as it iterates its operand.
  • List comprehensions may containe multiple for clauses to emulate nested loops.

Leave a Reply