YouTube

Session 8 of Software Lessons, “Programming in Python: Control Flow, Loops and Functions,” runs about 28 minutes.

What this session covers

  • Python variables, control flow, loops and function syntax
  • White space sensitivity
  • Declaring versus defining and assigning
  • Basic procedural programming in Python

Key ideas

  • A variable is a name bound to a value, and in Python assigning a value to a name is what creates the variable.
  • Control flow with if, elif and else chooses which block of code runs based on a condition.
  • A for loop repeats over a sequence of items, and a while loop repeats as long as a condition stays true.
  • Python uses indentation, not braces, to mark blocks, so consistent white space is part of the syntax.
  • A function groups code under a name so it can be reused with different inputs and can return a result.