Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b12e8b

Browse filesBrowse files
committed
@mmcky tidy up
1 parent e41321b commit 7b12e8b
Copy full SHA for 7b12e8b

File tree

Expand file treeCollapse file tree

2 files changed

+9
-34
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-34
lines changed
Open diff view settings
Collapse file

‎lectures/names.md‎

Copy file name to clipboardExpand all lines: lectures/names.md
+4-16Lines changed: 4 additions & 16 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -451,36 +451,30 @@ First,
451451
* The global namespace `{}` is created.
452452

453453
```{figure} /_static/lecture_specific/oop_intro/global.png
454-
:figclass: auto
455454
```
456455

457456
* The function object is created, and `g` is bound to it within the global namespace.
458457
* The name `a` is bound to `0`, again in the global namespace.
459458

460459
```{figure} /_static/lecture_specific/oop_intro/global2.png
461-
:figclass: auto
462460
```
463461

464462
Next `g` is called via `y = g(10)`, leading to the following sequence of actions
465463

466464
* The local namespace for the function is created.
467465
* Local names `x` and `a` are bound, so that the local namespace becomes `{'x': 10, 'a': 1}`.
466+
* Note that the global `a` was not affected by the local `a`.
468467

469-
* Note that the global `a` was not affected by the local `a`.
470468
```{figure} /_static/lecture_specific/oop_intro/local1.png
471-
:figclass: auto
472469
```
473470

474471

475472

476473
* Statement `x = x + a` uses the local `a` and local `x` to compute `x + a`, and binds local name `x` to the result.
477-
478-
479474
* This value is returned, and `y` is bound to it in the global namespace.
480475
* Local `x` and `a` are discarded (and the local namespace is deallocated).
481476

482477
```{figure} /_static/lecture_specific/oop_intro/local_return.png
483-
:figclass: auto
484478
```
485479

486480

@@ -528,21 +522,18 @@ Here's what happens
528522
* `f` is registered as a function in the global namespace
529523

530524
```{figure} /_static/lecture_specific/oop_intro/mutable1.png
531-
:figclass: auto
532525
```
533526

534527
* `x` bound to `[1]` in the global namespace
535528

536529
```{figure} /_static/lecture_specific/oop_intro/mutable2.png
537-
:figclass: auto
538530
```
539531

540532
* The call `f(x)`
541533
* Creates a local namespace
542534
* Adds `x` to the local namespace, bound to `[1]`
543535

544536
```{figure} /_static/lecture_specific/oop_intro/mutable3.png
545-
:figclass: auto
546537
```
547538

548539
```{note}
@@ -567,26 +558,23 @@ print(f(x), x)
567558
* Returns the list `[2]`
568559

569560
```{figure} /_static/lecture_specific/oop_intro/mutable4.png
570-
:figclass: auto
571561
```
572562
* The local namespace is deallocated, and the local `x` is lost
573563

574564
```{figure} /_static/lecture_specific/oop_intro/mutable5.png
575-
:figclass: auto
576565
```
577566

578567
If you want to modify the local `x` and the global `x` separately, you can create a [*copy*](https://docs.python.org/3/library/copy.html) of the list and assign the copy to the local `x`.
579568

580569
We will leave this for you to explore.
581570

582-
583571
## Summary
584572

585573
Messages in this lecture are clear:
586574

587-
* In Python, *everything in memory is treated as an object*.
588-
* Zero, one or many names can be bound to a given object.
589-
* Every name resides within a scope defined by its namespace.
575+
* In Python, *everything in memory is treated as an object*.
576+
* Zero, one or many names can be bound to a given object.
577+
* Every name resides within a scope defined by its namespace.
590578

591579
This includes not just lists, strings, etc., but also less obvious things, such as
592580

Collapse file

‎lectures/oop_intro.md‎

Copy file name to clipboardExpand all lines: lectures/oop_intro.md
+5-18Lines changed: 5 additions & 18 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -670,36 +670,28 @@ First,
670670
* The global namespace `{}` is created.
671671

672672
```{figure} /_static/lecture_specific/oop_intro/global.png
673-
:figclass: auto
674673
```
675674

676675
* The function object is created, and `g` is bound to it within the global namespace.
677676
* The name `a` is bound to `0`, again in the global namespace.
678677

679678
```{figure} /_static/lecture_specific/oop_intro/global2.png
680-
:figclass: auto
681679
```
682680

683681
Next `g` is called via `y = g(10)`, leading to the following sequence of actions
684682

685683
* The local namespace for the function is created.
686684
* Local names `x` and `a` are bound, so that the local namespace becomes `{'x': 10, 'a': 1}`.
685+
* Note that the global `a` was not affected by the local `a`.
687686

688-
* Note that the global `a` was not affected by the local `a`.
689687
```{figure} /_static/lecture_specific/oop_intro/local1.png
690-
:figclass: auto
691688
```
692689

693-
694-
695690
* Statement `x = x + a` uses the local `a` and local `x` to compute `x + a`, and binds local name `x` to the result.
696-
697-
698691
* This value is returned, and `y` is bound to it in the global namespace.
699692
* Local `x` and `a` are discarded (and the local namespace is deallocated).
700693

701694
```{figure} /_static/lecture_specific/oop_intro/local_return.png
702-
:figclass: auto
703695
```
704696

705697

@@ -747,21 +739,18 @@ Here's what happens
747739
* `f` is registered as a function in the global namespace
748740

749741
```{figure} /_static/lecture_specific/oop_intro/mutable1.png
750-
:figclass: auto
751742
```
752743

753744
* `x` bound to `[1]` in the global namespace
754745

755746
```{figure} /_static/lecture_specific/oop_intro/mutable2.png
756-
:figclass: auto
757747
```
758748

759749
* The call `f(x)`
760750
* Creates a local namespace
761751
* Adds `x` to the local namespace, bound to `[1]`
762752

763753
```{figure} /_static/lecture_specific/oop_intro/mutable3.png
764-
:figclass: auto
765754
```
766755

767756
```{note}
@@ -786,12 +775,10 @@ print(f(x), x)
786775
* Returns the list `[2]`
787776

788777
```{figure} /_static/lecture_specific/oop_intro/mutable4.png
789-
:figclass: auto
790778
```
791779
* The local namespace is deallocated, and the local `x` is lost
792780

793781
```{figure} /_static/lecture_specific/oop_intro/mutable5.png
794-
:figclass: auto
795782
```
796783

797784
If you want to modify the local `x` and the global `x` separately, you can create a [*copy*](https://docs.python.org/3/library/copy.html) of the list and assign the copy to the local `x`.
@@ -803,9 +790,9 @@ We will leave this for you to explore.
803790

804791
Messages in this lecture are clear:
805792

806-
* In Python, *everything in memory is treated as an object*.
807-
* Zero, one or many names can be bound to a given object.
808-
* Every name resides within a scope defined by its namespace.
793+
* In Python, *everything in memory is treated as an object*.
794+
* Zero, one or many names can be bound to a given object.
795+
* Every name resides within a scope defined by its namespace.
809796

810797
This includes not just lists, strings, etc., but also less obvious things, such as
811798

@@ -908,7 +895,7 @@ boolean object `True`.
908895
```{hint}
909896
:class: dropdown
910897
911-
You can use `callable()` to test whether an attribute of an object can be called as a function
898+
You can use `callable()` to test whether an attribute of an object can be called as a function
912899
```
913900

914901
```{exercise-end}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.