Chapter 8 Namespaces and Memory Realities

Slides:



Advertisements
Similar presentations
Solving Equations In Quadratic Form There are several methods one can use to solve a quadratic equation. Sometimes we are called upon to solve an equation.
Advertisements

Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
COSC 235: Programming and Problem Solving Chapter 1: The magic of Python Instructor: Dr. X 1.
Chapter 7 Lists and Tuples. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Data Structures.
Lists and Tuples Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Numerical Representation Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Number Representation, Data Types and Elementary Programming Shirley Moore CS 1401 February 5-7, 2013.
CIT 590 Intro to Programming Lecture 5 – completing lists.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Lecture 04 – Models of memory Mutable and immutable data.
Tuples and Dictionaries Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Dictionaries Intro to Computer Science CS 1510 Dr. Sarah Diesburg.
CSV Files Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Problem Solving Intro to Computer Science CS1510 Dr. Sarah Diesburg 1.
More Functional Decomposition
Topics Introduction to Repetition Structures
Thinking about programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Solving Equations: The Multiplication Principle
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 8 Namespaces and Memory Realities
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
More Nested Loops and Lab 5
Seek Method and CSV Files
Lists – Indexing and Sorting
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
More Functional Decomposition
Types, Truth, and Expressions (Part 2)
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More Functional Decomposition
Chapter 8 Namespaces and Memory Realities
Seek Method and CSV Files
Intro to Computer Science CS1510 Dr. Sarah Diesburg
5.2 Verifying Trigonometric Identities
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Augmented assignment operators Taken from notes by Dr. Neil Moore
Introduction to Strings
Reference semantics, variables and names
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Thinking about programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More Functional Decomposition
Lists – Indexing and Sorting
Intro to Computer Science CS1510 Dr. Sarah Diesburg
2 Chapter Chapter 2 Equations, Inequalities and Problem Solving.
Functions By Anand George.
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Objects Management.
More Functional Decomposition
Tuple.
Presentation transcript:

Chapter 8 Namespaces and Memory Realities Intro to Computer Science CS1510 Dr. Sarah Diesburg

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

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)

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.

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.

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

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

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.