Skip to content

Commit fe42b93

Browse files
committed
misc
1 parent 5fe985b commit fe42b93

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

lectures/names.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,20 @@ After binding the name `g` to the same object, we can use it anywhere we would u
7575

7676
What happens when the number of names bound to an object goes to zero?
7777

78-
Here's an example of this situation, where the name `x` is first bound to one object and then rebound to another
78+
Here's an example of this situation, where the name `x` is first bound to one object and then **rebound** to another
7979

8080
```{code-cell} python3
8181
x = 'foo'
8282
id(x)
83+
x = 'bar'
84+
id(x)
8385
```
8486

85-
```{code-cell} python3
86-
x = 'bar' # No names bound to the first object
87-
```
87+
In this case, after we rebind `x` to `'bar'`, no names bound are to the first object `'foo'`.
8888

89-
What happens here is that the first object is garbage collected.
89+
This is a trigger for `'foo'` to be garbage collected.
9090

91-
In other words, the memory slot that stores that object is deallocated, and returned to the operating system.
91+
In other words, the memory slot that stores that object is deallocated and returned to the operating system.
9292

9393
Garbage collection is actually an active research area in computer science.
9494

@@ -151,7 +151,7 @@ mathfoo.pi
151151

152152
These two different bindings of `pi` exist in different namespaces, each one implemented as a dictionary.
153153

154-
We can look at the dictionary directly, using `module_name.__dict__`
154+
If you wish, you can look at the dictionary directly, using `module_name.__dict__`.
155155

156156
```{code-cell} python3
157157
import math
@@ -162,7 +162,7 @@ math.__dict__.items()
162162
```{code-cell} python3
163163
import mathfoo
164164
165-
mathfoo.__dict__.items()
165+
mathfoo.__dict__
166166
```
167167

168168
As you know, we access elements of the namespace using the dotted attribute notation
@@ -171,10 +171,10 @@ As you know, we access elements of the namespace using the dotted attribute nota
171171
math.pi
172172
```
173173

174-
In fact this is entirely equivalent to `math.__dict__['pi']`
174+
This is entirely equivalent to `math.__dict__['pi']`
175175

176176
```{code-cell} python3
177-
math.__dict__['pi'] == math.pi
177+
math.__dict__['pi']
178178
```
179179

180180
## Viewing Namespaces
@@ -524,7 +524,7 @@ Here's what happens
524524
```{figure} /_static/lecture_specific/oop_intro/mutable1.png
525525
```
526526

527-
* `x` bound to `[1]` in the global namespace
527+
* `x` is bound to `[1]` in the global namespace
528528

529529
```{figure} /_static/lecture_specific/oop_intro/mutable2.png
530530
```

lectures/oop_intro.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,11 @@ inspect(10, methods=True)
277277

278278
In fact there are still more methods, as you can see if you execute `inspect(10, all=True)`.
279279

280+
281+
280282
## A Little Mystery
281283

282-
In this lecture we claimed that Python is object oriented.
284+
In this lecture we claimed that Python is, at heart, an object oriented language.
283285

284286
But here's an example that looks more procedural.
285287

@@ -289,13 +291,12 @@ m = len(x)
289291
m
290292
```
291293

292-
If Python is object oriented, why don't we use `x.len()`? Isn't this
293-
inconsistent?
294+
If Python is object oriented, why don't we use `x.len()`?
294295

295-
The answers are related to the fact that Python aims for consistent style.
296+
The answer is related to the fact that Python aims for readability and consistent style.
296297

297298
In Python, it is common for users to build custom objects --- we discuss how to
298-
do this [later](python_oop)`.
299+
do this {doc}`later <python_oop>`.
299300

300301
It's quite common for users to add methods to their that measure the length of
301302
the object, suitably defined.
@@ -305,10 +306,10 @@ When naming such a method, natural choices are `len()` and `length()`.
305306
If some users choose `len()` and others choose `length()`, then the style will
306307
be inconsistent and harder to remember.
307308

308-
To avoid this, the creator of Python chose to have some built-in functions
309-
like `len()`, to make clear that `len()` is the convention.
309+
To avoid this, the creator of Python chose to add
310+
`len()` as a built-in function, to help emphasize that `len()` is the convention.
310311

311-
Now, having said all of this, Python still is object oriented under the hood.
312+
Now, having said all of this, Python *is* still object oriented under the hood.
312313

313314
In fact, the list `x` discussed above has a method called `__len__()`.
314315

@@ -341,7 +342,8 @@ This includes not just lists, strings, etc., but also less obvious things, such
341342
* files opened for reading or writing
342343
* integers, etc.
343344

344-
345+
Remember that everything is an object will help you interact with your programs
346+
and write clear Pythonic code.
345347

346348
## Exercises
347349

0 commit comments

Comments
 (0)