Week_10_References

Week_10_References - CMPT120 J. Ye References to Lists and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPT120 J. Ye References to Lists and Strings -- Topic 5.6 in the Study Guide References to Objects Aliases to Lists and Strings When Lists are Passed to Functions … CMPT120 J. Ye 1 References to Objects Python is an object-oriented language. For now, you don’t have to worry about what is an object. Just remember: in Python , all the instances(values) of type int, float, string, list, … basically everything, are objects . E.g. 5 is an int type object “hello” is a string type object [1, 2, 3] is a list type object Thus, when you see the word object, you can just replace it with number, truth value, string, or list, … 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
J. Ye A Python variable always holds a reference to an object. A reference is a pointer to an object, or: A reference is a memory address of an object. Thus, a reference is a (special) value that can be kept in a variable E.g. lst = [1,2] variable name type value lst list References to Objects (cont) 3 [1, 2] heap: A heap is an area of memory where objects are stored. Each object has an unique address in the heap; that address can be (the value) stored in a variable as a reference pointing to the object. We could use id function to query that address. E.g., >>> lst = [1,2] >>> id(lst) 18937296 # this is the value (memory address) the little # box on the previous slide represents. # every time you re-run it, this value may vary
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/28/2011 for the course CMPT 125 taught by Professor Diana during the Spring '08 term at Simon Fraser.

Page1 / 9

Week_10_References - CMPT120 J. Ye References to Lists and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online