Memory in Python - Cornell University

Lecture 10

Memory in Python

Announcements For This Lecture

Reading

? Reread all of Chapter 3

Assignments

? Some A1s still unfinished

? Finish these ASAP ? Ideally done by Monday

? A2 now posted

? Do not start until A1 done ? Due after Fall Break ? Uses material from Monday ? New topic: reading a file

9/29/17

Memory in Python

2

Modeling Storage in Python

? Global Space

Global Space

? What you "start with" ? Stores global variables ? Also modules & functions! ? Lasts until you quit Python

p

id2

Call Frame

incr_x

? Call Frame

? Variables in function call ? Deleted when call done

? Heap Space

? Where "folders" are stored ? Have to access indirectly

q

id2

id2 x 1.0

Heap Space

Point3

y 2.0 x 3.0

9/29/17

Memory in Python

3

Memory and the Python Tutor

Global Space

Heap Space

Call Frame

9/29/17

Memory in Python

4

Functions and Global Space

? A function definition...

? Creates a global variable (same name as function)

? Creates a folder for body ? Puts folder id in variable

def to_centigrade(x): return 5*(x-32)/9.0

Global Space

to_centigrade id6

Body

? Variable vs. Call

Heap Space

>>> to_centigrade >>> to_centigrade (32) 0.0

id6

function

Body

9/29/17

Memory in Python

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download