GitHub

Original file line numberDiff line numberDiff line change

@@ -0,0 +1 @@

1+

pi = 'foobar'

Original file line numberDiff line numberDiff line change

@@ -0,0 +1 @@

1+

print(__name__)

Original file line numberDiff line numberDiff line change

@@ -9,7 +9,7 @@ kernelspec:

99

name: python3

1010

---

1111
12-

(oop_intro)=

12+

(oop_names)=

1313

```{raw} jupyter

1414

<div id="qe-notebook-header" align="right" style="text-align:right;">

1515

<a href="https://quantecon.org/" title="quantecon.org">

@@ -18,19 +18,8 @@ kernelspec:

1818

</div>

1919

```

2020
21-

<style>

22-

.auto {

23-

width: 100%;

24-

height: auto;

25-

}

26-

</style>

27-
2821

# OOP I: Names and Namespaces

2922
30-

```{contents} Contents

31-

:depth: 2

32-

```

33-
3423

## Overview

3524
3625

This lecture is all about variable names, how they can be used and how they are

@@ -42,7 +31,7 @@ handling names is elegant and interesting.

4231

In addition, you will save yourself many hours of debugging if you have a good

4332

understanding of how names work in Python.

4433
45-

(name_res)=

34+

(var_names)=

4635

## Variable Names in Python

4736
4837

```{index} single: Python; Variable Names

Original file line numberDiff line numberDiff line change

@@ -18,19 +18,8 @@ kernelspec:

1818

</div>

1919

```

2020
21-

<style>

22-

.auto {

23-

width: 100%;

24-

height: auto;

25-

}

26-

</style>

27-
2821

# OOP I: Names and Objects

2922
30-

```{contents} Contents

31-

:depth: 2

32-

```

33-
3423

## Overview

3524
3625

The traditional programming paradigm (think Fortran, C, MATLAB, etc.) is called [procedural](https://en.wikipedia.org/wiki/Procedural_programming).

@@ -714,8 +703,8 @@ Next `g` is called via `y = g(10)`, leading to the following sequence of actions

714703

```

715704
716705
717-

(mutable_vs_immutable)=

718-

### {index}`Mutable <single: Mutable>` Versus {index}`Immutable <single: Immutable>` Parameters

706+

(mutable_vs_immutable2)=

707+

### {index}`Mutable <single: Mutable>` versus {index}`Immutable <single: Immutable>` parameters

719708
720709

This is a good time to say a little more about mutable vs immutable objects.

721710
Original file line numberDiff line numberDiff line change

@@ -0,0 +1,8 @@

1+

def g(x):

2+

a = 1

3+

x = x + a

4+

return x

5+
6+

a = 0

7+

y = g(10)

8+

print("a = ", a, "y = ", y)

Read the original on github.com ↗