Skip to content

Commit 9478df5

Browse files
authored
Merge pull request #235 from QuantEcon/objects-fixes
Objects fixes
2 parents 9af3667 + f5bd387 commit 9478df5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lectures/python_fundamentals/functions.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ kernelspec:
1111

1212
# Functions
1313

14+
**Co-author**
15+
> - [Philip Solimine, *UBC*](https://www.psolimine.net)
16+
1417
**Prerequisites**
1518

1619
- {doc}`Getting Started <../introduction/getting_started>`
@@ -637,7 +640,7 @@ We are used to defining variables like `x = dict("a": 1, "b": 2)` and then using
637640
For example, a simple class that stores two variables would look like this:
638641

639642
```{code-cell} python
640-
class A:
643+
class MyType:
641644
def __init__(self, x, y):
642645
self.x = x
643646
self.y = y
@@ -648,13 +651,13 @@ Used both internal and external to classes, the `__init__` method is a special m
648651
A class, defined by the `class` keyword, is a blueprint for an object. It defines the attributes and methods that an object will have. An object is an instance of a class that has been created and assigned to a variable. It is created by calling the class name as if it were a function. When you call the class name, the object is created and the `__init__` method is called by default.
649652

650653
```{code-cell} python
651-
a = A(1, 2)
652-
b = A(3, 4)
653-
# Notice that these are different objects
654+
a = MyType(1, 2)
655+
b = MyType(3, 4)
656+
# Notice that these are different objects, even though they are the same type!
654657
a == b
655658
```
656659

657-
You can see that `a` and `b` are both instances of the `A` class by using the `type` function.
660+
You can see that `a` and `b` are both instances of the `MyType` class by using the `type` function.
658661

659662
```{code-cell} python
660663
type(a)
@@ -670,7 +673,7 @@ In addition to attributes, objects can also have methods. Methods are functions
670673

671674

672675
```{code-cell} python
673-
class B:
676+
class MyAdder:
674677
def __init__(self, x, y):
675678
self.x = x
676679
self.y = y
@@ -679,10 +682,10 @@ class B:
679682
return self.x + self.y
680683
```
681684

682-
We can now create an object of type `B` and call the `add` method, in the same way that we called methods on built-in types (like the `.upper()` method on a string.)
685+
We can now create an object of type `MyAdder` and call the `add` method, in the same way that we called methods on built-in types (like the `.upper()` method on a string.)
683686

684687
```{code-cell} python
685-
b = B(1, 2)
688+
b = MyAdder(1, 2)
686689
print(b.add())
687690
```
688691

lectures/scientific/randomness.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ kernelspec:
1111

1212
# Randomness
1313

14+
**Co-author**
15+
> - [Philip Solimine, *UBC*](https://www.psolimine.net)
16+
1417
**Prerequisites**
1518

1619
- {doc}`Introduction to Numpy <numpy_arrays>`

0 commit comments

Comments
 (0)