Presentation is loading. Please wait.

Presentation is loading. Please wait.

UW CSE 190p Section 8/2, Summer 2012 Dun-Yu Hsiao.

Similar presentations


Presentation on theme: "UW CSE 190p Section 8/2, Summer 2012 Dun-Yu Hsiao."— Presentation transcript:

1 UW CSE 190p Section 8/2, Summer 2012 Dun-Yu Hsiao

2 Outlines Function: id(.) Mutable and immutable types Quiz walkthrough Homework question

3 Memory Visualization

4 Function: id(.) Return the “identity” of an object. Show the address of the object in memory. An integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime.

5 Immutability By immutability, we mean that whenever we start manipulating a immutable item, Python will spawn off another value for us.

6 Immutability Example x = 300 y = 300 s = 'a string' t = ('a', 'tuple')

7 Mutability For mutable types, we can actually change the value where it's stored in memory.

8 Mutability Example l = [1, 2, 3]

9 Mutable and Immutable Types Mutable types: – list, dictionary Immutable types: – Int, float, string, tuple

10 Quiz Walkthrough Assume these definitions: y = 4 def double(y): return y + y Evaluate the following expression. Show every step. y + double(3 * y)

11 Quiz Walkthrough y = 3 def double(y): return y + y def quadruple1(y): return double(double(y)) def quadruple2(y): return double(y) + double(y) def quadruple3(y): return y + y + y + y double(y) + quadruple1(double(y) + y)

12 Quiz Walkthrough y = 3 def double(y): return y + y def quadruple1(y): return double(double(y)) def quadruple2(y): return double(y) + double(y) def quadruple3(y): return y + y + y + y double(y) + quadruple2(double(y) + y)

13 Quiz Walkthrough y = 3 def double(y): return y + y def quadruple1(y): return double(double(y)) def quadruple2(y): return double(y) + double(y) def quadruple3(y): return y + y + y + y double(y) + quadruple3(double(y) + y)

14 Homework/Quiz Questions?


Download ppt "UW CSE 190p Section 8/2, Summer 2012 Dun-Yu Hsiao."

Similar presentations


Ads by Google