Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lectures/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ kernelspec:

## Overview

Functions are an extremely useful construct provided by almost all programming.
Functions are an extremely useful construct provided by almost all programming languages.

We have already met several functions, such as

Expand All @@ -35,7 +35,7 @@ We have already met several functions, such as
In this lecture we'll

1. treat functions systematically and cover syntax and use-cases, and
2. learn to do is build our own user-defined functions.
2. learn how to build our own user-defined functions.

We will use the following imports.

Expand Down Expand Up @@ -360,7 +360,7 @@ Notes

Now, there are several ways that we can simplify the code above.

For example, we can get rid of the conditionals all together by just passing the desired generator type as a function, method, or other [callable](https://typing.python.org/en/latest/spec/callables.html) object.
For example, we can get rid of the conditionals altogether by just passing the desired generator type as a function, method, or other [callable](https://typing.python.org/en/latest/spec/callables.html) object.

To understand this, consider the following version.

Expand Down Expand Up @@ -669,8 +669,7 @@ print([x(i) for i in range(10)])
:label: func_ex5
```

Rewrite the function `factorial()` in from [Exercise 1](factorial_exercise) using recursion.

Rewrite the function `factorial()` from [Exercise 1](factorial_exercise) using recursion.
```{exercise-end}
```

Expand Down
6 changes: 3 additions & 3 deletions lectures/oop_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ When Python creates this integer object, it stores with it various auxiliary inf

Any name following a dot is called an *attribute* of the object to the left of the dot.

* e.g.,``imag`` and `__class__` are attributes of `x`.
* e.g., `imag` and `__class__` are attributes of `x`.

We see from this example that objects have attributes that contain auxiliary information.

Expand Down Expand Up @@ -299,7 +299,7 @@ The answer is related to the fact that Python aims for readability and consisten
In Python, it is common for users to build custom objects --- we discuss how to
do this {doc}`later <python_oop>`.

It's quite common for users to add methods to their that measure the length of
It's quite common for users to add methods to their objects that measure the length of
the object, suitably defined.

When naming such a method, natural choices are `len()` and `length()`.
Expand Down Expand Up @@ -343,7 +343,7 @@ This includes not just lists, strings, etc., but also less obvious things, such
* files opened for reading or writing
* integers, etc.

Remember that everything is an object will help you interact with your programs
Remembering that everything is an object will help you interact with your programs
and write clear Pythonic code.

## Exercises
Expand Down
8 changes: 4 additions & 4 deletions lectures/python_oop.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Before we do so, in order to indicate some of the power of Classes, we'll define

```{code-cell} python3
def earn(w,y):
"Consumer with inital wealth w earns y"
"Consumer with initial wealth w earns y"
return w+y

def spend(w,x):
Expand Down Expand Up @@ -186,7 +186,7 @@ print("w0,w1,w2,w3,w4 = ", w0,w1,w2,w3,w4)

A *Class* bundles a set of data tied to a particular *instance* together with a collection of functions that operate on the data.

In our example, an *instance* will be the name of particular *person* whose *instance data* consist solely of its wealth.
In our example, an *instance* will be the name of a particular *person* whose *instance data* consist solely of its wealth.

(In other examples *instance data* will consist of a vector of data.)

Expand All @@ -206,7 +206,7 @@ We'll build a `Consumer` class with

Admittedly a little contrived, this example of a class helps us internalize some peculiar syntax.

Here how we set up our Consumer class.
Here's how we set up our Consumer class.

```{code-cell} python3
class Consumer:
Expand All @@ -223,7 +223,7 @@ class Consumer:
"The consumer spends x dollars if feasible"
new_wealth = self.wealth - x
if new_wealth < 0:
print("Insufficent funds")
print("Insufficient funds")
else:
self.wealth = new_wealth
```
Expand Down