1 / 17

Chapter 8 Namespaces and Memory Realities

Chapter 8 Namespaces and Memory Realities. Intro to Computer Science CS1510 Dr. Sarah Diesburg. Questions. Any questions over yesterday’s lab? Any questions over PA08. Namespaces. You can think of a namespace as where a name is valid and can be used

gabriellam
Télécharger la présentation

Chapter 8 Namespaces and Memory Realities

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. Chapter 8Namespaces and Memory Realities Intro to Computer Science CS1510 Dr. Sarah Diesburg

  2. Questions • Any questions over yesterday’s lab? • Any questions over PA08

  3. Namespaces • You can think of a namespace as where a name is valid and can be used • Two functions can use a variable with the same name. These are two separate variables. • Let me show you a short demo. • Explaining the “separate ” part requires a bit more explanation

  4. How Python stores information(HEAVY) • Objects are Python’s abstraction for data. • All data in a Python program is represented by objects or by relations between objects. • Every object has: • an identity (Where it is in memory. Unchangeable) • a type (How to interpret memory. Unchangeable) • a value (What is in memory. May (not) be changeable)

  5. Reminder: Assignment • Assignment takes an object (the final object after all operations) from the right-hand-side and associates it with a variable on the left-hand side. • When you assign one variable to another, you share the association with the same object.

  6. Immutables • Object sharing, two variables associated with the same object, is not a problem since the object cannot be changed. • Any changes that occur generate a new object.

  7. Mutability Changes an Object • If two variables associate with the same object, then both reflect any change to that object.

  8. Copying If we copy, does that solve the problem? myLst = [1, 2, 3] newLst = myLst[:]

  9. The Problem is What Gets Copied… • The elements of the list are copied, but sometimes the elements of the list themselves are references (or associations). • If the list has nested lists or uses other associations, the association gets copied. This is termed a shallow copy.

More Related