This module covers several fundamental aspects of Python: statements, expressions, variables, conditionals, loops, functions, and exceptions.

Learning Outcomes

After completing this module, students should understand

  • What statements and expressions are and the differences between them

  • The difference between simple and compound statements and the elements of a compound statement

  • Common operators in Python, including the various division-related operators

  • How to declare and modify variables in Python

  • What a boolean context is and how common values are treated in boolean contexts

  • How to write conditional statements and conditional expressions and how they are different

  • How to write while loops and for loops and when to choose one over the other

  • How to alter the normal flow of control in a loop

  • How to call a function

  • The difference between positional arguments and keyword arguments and how to use each of them

  • How to write a function

  • The difference between required parameters and optional parameters and how to declare each of them

  • The difference between return and print()

  • What function docstrings are and how to write them

  • What an exception is

  • How the Python call stack works and how to read a stack traceback

  • How to raise exceptions

  • How to handle exceptions with try/except statements

Additional Readings