Skip to content
- Lab 00: Getting Started (06/05/22)
- Terminal commands
- ls: lists all files in the current directory
- cd <path to directory>: change into the specified directory
- mkdir <directory name>: make a new directory with the given name
- mv <source path> <destination path>: move the file at the given source
to the given destination
- Python basics
- Expression: a piece of code that evaluates to some value
- Statement: one or more lines of code that make something happen in a
program
- Arithmetic operators
- +, -, *, **(exponentiation), / (float division), // (floor division),
% (modulo)
- Comments
- """ blabla """: docstring
- >>> <Python expressions> : doctests with output printed below
- Variable swap: a, b = b, a
- Evaluate everything on the right before simultaneouly assigning them
to their respective new names
- Lecture 1: Functions (06/05/22)
- Reading Ch. 1.1: Getting Started (07/05/22)
- Statements and expressions carry out actions and evaluate to a value
- Functions encapsulate logic that manipulates data
- Objects bundle data and the logic manipulating it
- Interpreter is a program that implements a precise procedure to
interpret code in a predictable way so as to evaluate compound expressions
- Debugging principles: Test incrementally, isolate errors, check your
assumptions, and consult others
- Reading Ch. 1.2: Elements of Programming (07/05/22)
- Means of combining simple ideas into complex ones: primitive expressions and
statements, means of combination, and means of abstraction
- Modules are groups of classes, variables, and functions
- All functions and variables in Python are called attributes, which is
not found in other languages
- Assignment is the simplest means of abstraction: bind names to
values
- Environment is the memory that keeps track of names, values, and their
bindings
- Unlike other languages, Python can bind built-in names to new values
- Pure vs non-pure functions
- Pure functions have no effects other than returning a value
- Non-pure functions return values and make changes to the state of the
interpreter or computer
- Lecture 2: Names (07/05/22)
- Environment diagrams visualize the interpreter’s process

- Function definition is a more powerful means of abstraction than
assignment: bind names to expressions
- Parameters: names of values passed into a function
- Arguments: specific values of parameters
- Defining functions
- Create a function with signature <name>(<formal parameters>)
- Set the body of the function
- Bind <name> to that function in the current frame
- Calling user-defined functions
- Add a local frame, forming a new environment
- Bind the function’s parameters to its arguments in that frame
- Execute the function’s body in the new environment

- Environment: a sequence of frames, either:
- The global frame alone, or
- A local, then the global frame
- The local frame has the global frame as its parent
- Frame: a binding between names and values
- A name evaluates to the value bound to that name in the earliest frame of the
current environment

- Homework 01: (07/05/22)
- Evaluating a call expression in Python
- Evaluate the operator and operand subexpressions, then
- Apply the function
- Discussion 01: Control, Environment Diagrams (15/07/22)