Questions
Describe the difference between objects and values using the terms “equivalent” and “identical”. Illustrate the difference using your own examples with Python lists and the “is” operator.
Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.
Finally, create your own example of a function that modifies a list passed in as an argument. Describe what your function does in terms of arguments, parameters, objects, and references
1. Question 1
Question:
Describe the difference between objects and values using the terms “equivalent” and “identical”. Illustrate the difference using your own examples with Python lists and the “is” operator.
Answer:
A value is: “One of the basic units of data, like a number or string, that a program manipulates” (Downey, 2015, p. 7). An object is: “Something a variable can refer to, and it has a type and a value” (Downey, 2015, p. 100). The meaning of equivalent is: “Having the same value” (Downey, 2015, p. 100). The meaning of identical is: “Being the same object (which implies equivalence)” (Downey, 2015, p. 100).
Therefore, the difference between objects and values is: An object has a value and a type; suppose there are two lists. If they have the same object, they are identical, which also means they have the same value. But if they only have the same value, and the objects are different, they are equivalent but not identical.
The example of two equivalent lists:
1 | str1 = ['I', 'love', 'Python'] |
For the above example, I defined two lists, namely list1 and list2. They have the same value “I”, “love”, and “Python”, but when I use the is operator to check whether they are the same object, the return value is False, which shows their objects are different. Therefore, the two lists have the same value but different objects, so they are equivalent.
The example of two identical lists:
1 | str1 = ['I', 'love', 'Python'] |
For the above example, I defined list1 and then assigned list1 to list2. When I use the is operator to check whether they are the same object, the return value is True, which indicates that their objects are the same. Furthermore, when I use the Print function to check whether list1 and list2 have the same value, the result shows that their values are also the same. Therefore, the two lists have the same object, which means they have the same value and type. Consequently, they are identical.
2. Question 2
Question:
Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists.
Answer:
An object is: “Something a variable can refer to, and it has a type and a value” (Downey, 2015, p. 100). The reference is: “The association between a variable and its value” (Downey, 2015, p. 100). The aliasing is: “A circumstance where two or more variables refer to the same object” (Downey, 2015, p. 100). Therefore, the relationship between objects, references, and aliasing is: a reference is an association between a variable and its object. If an object has more than two names, this circumstance is called aliasing.
An example of Python list:
1 | t1 = ['a', 'b', 'c'] |

For the above example, I defined a list [‘a’, ‘b’, ‘c’] and assigned it to the variable t1, and then I assigned list t1 to the variable t2. The object is something the variable t1 and t2 refer to; the reference is the association between the variable t1(t2) and the value [‘a’, ‘b’, ‘c’]; the aliasing is the circumstance where the variable t1 and t2 refer to the same object.
3. Question 3
Question:
Finally, create your own example of a function that modifies a list passed in as an argument. Describe what your function does in terms of arguments, parameters, objects, and references.
Answer:
The example of the function uppercase that modifies a list passed in as an argument:
1 | def uppercase(t): |
The description of what the function does:
The function uppercase capitalizes the elements of a list. Specifically, I created the list [‘i’, ‘love’, ‘python’] and assigned it to the variable t1. Then I passed t1 as the argument to the parameter t of the function uppercase. In this way, the function got a reference to the list, and the parameter t1 and the variable t became the aliases for the same object (Downey, 2015). When I call the function with the list t1 passing to it, the list t1 will be changed inside the function. So, when I print the return value outside the function, the list’s elements are uppercased.
Word count: 748
References
1.Downey, A. (2015). Think Python. Green Tea Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf