1 / 14

UW CSE 190p Section

UW CSE 190p Section. 8/2, Summer 2012 Dun-Yu Hsiao. Outlines. Function: id(. ) Mutable and immutable types Quiz walkthrough Homework question. Memory Visualization. Function: id(.). Return the “identity” of an object . Show the address of the object in memory .

carl
Download Presentation

UW CSE 190p Section

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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?

More Related