{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
CMPT120 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern