Syllabus for all weeks#

Syllabus week 1: Introduction#

Basic syntax and terminology:

  • A program is a text with a sequence of commands executed line-by-line

  • Each time a program runs, it starts with a clean slate (no previous definitions)

  • Python programs are saved as text files with a .py extension

  • Syntax guidelines: comments, blank lines, indentation, and case sensitivity

Some ways to execute Python code:

  • Script mode in IDLE (practical knowledge: you should acquire this skill)

  • Jupyter notebooks and cell mode for some IDES (conceptual knowledge)

  • Running Python code directly in a browser

Key concepts introduced through examples, no formal definition yet:

  • Assignments

  • The print() function

  • String variables

  • Inputs to a function (later referred to as arguments)

  • Numeric variables for integers and floats

  • Common numeric operators: +, -, *, **, /

  • Operator precedence and the use of parentheses to control precedence.

  • Simple functions: abs(), round()

  • Output of functions (later referred to as returned values)

Syllabus week 2: Variables and types#

  • Concept of statement illustrated by the print statement and assignment statement.

  • Assignments and assignment operator = (formal definition)

  • The concept of expression.

  • Variables and types (formal definition)

  • Valid variable names and naming conventions

  • The type() function

  • Concept of namespace (an informal definition)

  • Reassignments

  • Numeric data types: int, float

  • String data type, str with single or double quote

  • String operators + (concatenation) and * (repetition)

  • The len() function for strings

  • Type casting with int(), float(), str()

  • Numeric operators: % (modulus) and // (floor division)

  • Built-in-functions with multiple arguments: max(), min(), and print()

  • The math module

  • Via example keyword import and the import statement

  • Functions from the math module: math.sin(), math.cos(), math.sqrt(), math.exp(), math.log(), math.ceil(), math.floor().

  • Constant math.pi

  • Boolean data type and bool()

  • Comparison operators: ==, !=, <, >, <=, >=

  • Logical operators: and, or, not

  • Good practice, e.g. avoid print = 6

  • Understanding error messages

Syllabus week 3: Conditionals#

  • Conditional execution with if statements, keyword if followed by a Boolean expression

  • Controlling scope with indented block

  • Alternative execution with if-else statements, keyword else

  • Chained conditionals with if-elif-else statements, keyword elif

  • Nested conditionals

  • The concept of debugging

  • Debugging with print statement: using print() to trace and understand code execution

  • Identifying errors in code that runs but does not produce the expected output

  • Problem-solving by constructing the correct conditions

Syllabus week 4: Loops#

  • Looping over a sequence (known number of iterations), keyword for and keyword in, the range() function

  • Understanding that indexing variable in the for loop is reassigned with each iteration

  • Looping as long as a condition is true (unknown number of iterations), keyword while

  • Understanding that the variables used in the condition need to be defined before the while loop

  • Understanding that the variables used in the condition should be changed in the while loop body for loop to terminate

  • Keyword break

  • Solve simple problems that require a lot of computation e.g. simulations and population models

  • The concept of pseudocode

Syllabus week 5: Functions#

  • Functions, keyword def

  • Function names and naming convention

  • Function parameters (names given by the function definition)

  • Function arguments (values passed to the function when called)

  • Function body and indentation

  • Calling functions

  • Variable scope

  • Returning values, keyword return

  • Fruitful and void function, side effects, None type

  • Function examples: build-in functions, functions included in the standard Python library, functions from common third-party libraries, user-defined functions.

  • Tracebacks in error messages

  • Good practice when writing functions (start by scripting, incremental development, scaffolding)

  • Testing functions

  • Writing tests for functions

  • Documenting functions

Syllabus week 6: Lists#

  • Lists, a list is a sequence of values

  • Understanding sequences, elements, and indexes.

  • Creating lists: enclosing the elements in square brackets

  • List indexing

  • List slicing

  • Lists are mutable

  • The keyword is as identity operator vs. equality operator ==

  • List methods: append(), extend(), pop(), index(), sort(), count(), copy()

  • List operators: + (concatenate) and * (repeat)

  • Difference between modification and reassignment

  • Empty lists

  • Deleting list elements

  • Pure functions and modifier functions.

  • Functions min(), max(), sum(), len() and understanding functions that accept different data types

  • Traversing lists

  • Understanding that modifying the indexing variable does not affect the list

  • Constructor list() i.e. list('hej'), list(range(4))

  • Solving problems that involve custom searches within lists.

Syllabus week 7: Strings#

  • A string is a sequence of characters (each character itself is also a string), revisit sequences, elements, indices

  • String indexing

  • String slicing

  • Negative index

  • Methods and invoking a method

  • String methods: upper(), lower(), find(), index(), count(), strip()

  • Keyword in as a membership operator

  • Revisit the len() function for strings

  • Traversing strings, keyword in for traversal

  • f-strings, and string formatting options

  • Escape sequence, e.g. "/n"

  • String methods with lists as return value or argument: split() and join()

  • The repr() function and using it to display strings with escape sequences visible

Syllabus week 8: Dictionaries and tuples#

  • Dictionary, a collection of key-value pairs

  • Creating dictionaries: enclosing key-value pairs in curly brackets

  • Keyword in for dictionaries operates on keys, not values

  • Traversing a dictionary

  • Adding key-value pairs to the dictionary

  • Dictionaries are mutable

  • Tuple, an immutable sequence of values

  • Creating tuple with or without parenthesis

  • Unpacking, i.e a, b = my_function()

  • Using tuple as a return value

Syllabus week 9: Files#

  • Module os an interface to interact with the operating system

  • Current working directory os.getcwd()

  • Directory list os.listdir()

  • Check if the file exists os.path.isfile()

  • Relative and absolute paths

  • Function open() with 'r' and 'w'

  • Statement with and alias as for simplified handling of exceptions

  • Reading methods: read(), readline(), readlines()

  • Writing methods: write(), writeline()

  • More on string escape sequences and repr()

  • Other readers and writers (informationtional)

Syllabus week 10: Classes I#

  • Object-oriented programming (==P), structuring code to bundle properties and behavior.

  • Classes, templates for creating instances that share common attributes and methods.

  • Instances, concrete objects created from a class template.

  • Keyword class

  • Class naming convention

  • Attributes

  • Objects are mutable

  • Methods and the argument self

  • Method __init__()

Syllabus week 11: Classes II#

  • Inheritance and base class

  • Method __str__()

  • Inheritance

  • The super() function

  • Operator overloading example on __add__()

Syllabus week 12: Numpy and matplotlib#

  • Using Python in Polytechnic Foundation courses

  • Revisit Jupyter notebooks (what is it, similarities and differences to .py files)

  • NumPy, a library for numeric computing in Python, especially when handling large arrays and matrices. Via examples, we will cover:

    • NumPy array, an n-dimensional array

    • Compact syntax

    • Vectorized NumPy operators, for example +, *

    • NumPy functions for element-wise operations: numpy.sqrt(), numpy.exp(), numpy.sin(), numpy.abs()

    • Other functions and methods: numpy.mean(), numpy.std()

    • Indexing

    • NumPy arrays are mutable

    • Prealocation

    • Basic linear algebra

    • Boolean indexing

  • Matplotlib, a library for scientific visualization in Python. Via examples, we will cover:

    • Line plots

    • Bar plots

    • Labels

    • Legends

    • Titles

    • Text

Syllabus week 13: Modules#

  • User-made modules, using them and creating them

  • Import statement, standard import, selective import and alias import

  • Using pip to install third-party modules