3 Python Basics I - Variables & Functions (1 week)
Overview
This module will cover the use of variables and functions.
Objectives
At the conclusion of this Module students will be able to:
Make use of variables to represent simple types (i.e., int, float, char, and bool).
Make use of variables to store strings.
Write functions that accept zero or more arguments.
Write functions that return zero values.
Write functions that return one value.
Write functions that return multiple values.
Make use of modules to organize functions.
Document functions with Type Hints & pydoc.
Relevance
Variables and functions are required to write code in any language. This allows for data to be stored, computations to be performed, and (after the next module) resulted to be output.
This module will cover the use of print and input to output to the command line and read from the command line, respectively. Basic formatting will be discussed with an emphasis on f-string syntax.
Objectives
At the conclusion of this Module students will be able to:
Perform basic string manipulations (e.g., extract a substring).
Perform basic string comparison using built-in functions (e.g., startswith).
Extract data from user input (through input).
Write code that outputs to the command line.
Make use of f-string syntax to format output (e.g., alignment, decimal precision, number of digits).
Discuss the benefits of f-string syntax over the use of .format and % for formatting.
Relevance
For a program to be usable (i.e., have value) data must be output in a readable form. This output requires an understanding of the formatting mechanics of the selected language (in our case Python)
This Module will cover the basics of loops, conditional blocks, and command line arguments.
Objectives
At the conclusion of this Module students will be able to:
Extract data from command line arguments (through sys.argv).
Utilize while loops.
Utilize for loops.
Utilize conditional blocks that make use of if, elif, and else.
Relevance
An understanding of loops and conditional blocks is necessary to write any code that deals with large sets of data (e.g., assignment and grade data within Canvas).
6 Collections - Lists, Tuples, and Dictionaries (1 week)
Overview
This Module will focus on Python lists and tuples to store data. This will include lists that contain elements of a single type and lists with elements of different types. Dictionaries will be briefly introduced as a point of comparison. However, a full discussion will be left to a data structures course.
Objectives
At the conclusion of this Module students will be able to:
Compare Python lists to a Java/C++ arrays.
Utilize the list slice syntax.
Utilize List Comprehensions and generator expressions.
Compare lists and tuples in the context of mutability.
Make use of built-in functions such as sum, min, and max to perform aggregate operations on collections.
Make use of the built-in sort function.
Make use of the built-in sort function with a provided key argument.
Describe when a dictionary is appropriate over a list.
Relevance
To store, generate, and process information knowledge of how to select, interact with, and compose various data structures is necessary.
7 File IO, Context Managers, and Exceptions (1 week)
Overview
This Module will focus on working with files. This will include making use of context managers and handling exceptions such as ValueError and IndexError.
Objectives
At the conclusion of this Module students will be able to:
Write code to read data from a plaintext file
Write code to write data to a plaintext file
Make use of the with context manager to guarantee input and output files are closed
Discuss context managers in the context of scope
Write code to handle specific exceptions (e.g., ValueError)
Refactor code to make use of context managers.
Discuss why a single bare except that handles all possible exceptions is considered bad practice
Relevance
Most programs interact with files in some way (e.g., your IDE when writing Python code). Without a knowledge of how to read from and write to files… it is impossible to write code to solve all but the simplest of tasks.
8 Writing Pythonic Code, Code Linting, and Testing with PyTest (1 week)
Overview
There are many best practices applied in well written Python code. These are considered Pythonic. While an exhaustive list of practices cannot be covered in a single module… we can extend the PEP 8 and PEP 20 discussions from Module 2.
Objectives
Summarize how testing can be incorporated into the refactoring process
Discuss regression testing in the context of refactoring
Write tests for an existing codebase
Add pydoc documentation for an existing codebase
Discuss best practices for import statements
Discuss the benefits of isort, black and pytest
Discuss the functionality of isort, black and pytest
Identify style and naming issues in an existing codebase
Relevance
Well-written code allows is more readable and maintainable. Test Driven Development (TDD) is a stable of modern development.
In this Module we will discuss the basics of separating Python code into multiple .py files. We will also discuss best practices for writing Python classes.
Objectives
After completing this module students will be able to:
Map existing knowledge of object oriented C++ or Java onto Python.
Utilize properties and setters.
Explain how to implement __eq__ and __hashcode__.
Explain how to implement __str__.
Define the concept of a Python module and compare it to a Java package or C++ namespace.
Apply the D.R.Y principle.
Summarize the justification for a formal class checklist.
Describe the emergent nature of a class checklist.
Relevance
There are many options for writing classes in Python (e.g., from scratch, with an @dataclass decorator). Familiarity with these aforementioned options along with a knowledge of separating code into modules are expected on software engineering projects.
10 Polymorphism, Interfaces, and Protocols (1 week)
Overview
This module discusses the notion of Inheritance in OOP. This includes an
exploration subtyping as it relates to inheritance
introduction to function overriding.
Objectives
After completing this module students will be able to:
Summarize the difference between inheritance and subtyping.
Implement the Python deep copy (i.e., __deepcopy__) alongside an inheritance hierarchy.
Discuss Protocols vs. ABCs.
Discuss Liskov substitution (S.O.L.I.D.).
Explain how to implement __iter__.
Describe the use of an inner class in the context of abstraction and encapsulation.
Apply the principles defined by S.O.L.I.D.
Relevance
Almost all modern code makes use of Iterators, Collections, and Protocols. The ability to recognize these abstractions, design code around them, and make use of them from external libraries is a fundamental skill in software engineering.
While Python does technically have an array type, it is not used by most Python projects. In most numerical applications, NumPy is used due to its performance, built-in functionality, and numpy.array.
Objectives
At the conclusion of this Module students will be able to:
Create an empty (uninitialized) numpy.array.
Create a numpy.array initialized to all zeroes.
Create a numpy.array initialized to all ones.
Create a numpy.array of ints from a Python list.
Create a numpy.array of floats from a Python list.
Obtain the dimensions of a numpy.array using shape .
Write and rewrite code to make use of NumPy’s broadcast functionality in place of a loop.
Perform basic statistical analysis (e.g., mean, min, max, and standard deviation) using NumPy.
Explain the axis parameter.
Summarize the performance (runtime and memory utilization) of NumPy in comparison the Python lists.
Relevance
Well-known data science libraries, such as Pandas, rely on NumPy. Even if you do not create NumPy arrays directly… you will still end up working with them.
This is a Pseudo-Module. There is no new material (e.g., languages, paradigms or patterns) covered. This Module is an end-of-semester wrap up. We will revisit selected topics and lectures from throughout the semester.
Lectures and topics from the entire course will be covered on the Final Exam. The lectures listed here serve as a good starting point for a final review. Use them to determine how much time you need to dedicated to reviewing each module.
Modules 10 and 11 were covered fairly recently. Be sure to go back through both modules as part of your review.