In this project, I studied object instantiation in Python, delving into variable aliasing and object identifiers, types, and mutability. The project involved a series of quiz-like questions the answers to which I provided in single-line .txt files.
- 0. Who am I?
- 0-answer.txt: What function would you use to print the type of an object?
- 1. Where are you?
- 1-answer.txt: How do you get a variable's identifier (which is the memory address in the CPython implementation)?
- 2. Right count
- 2-answer.txt: In the following code, do a and b point to the same object?
- 3. Right count =
- 3-answer.txt: In the following code, do a and b point to the same object?
- 5. Right count =+
- 5-answer.txt: In the following code, do a and b point to the same object?
- 6. Is equal
- 6-answer.txt: What do these 3 lines print?
- 7. Is the same
- 7-answer.txt: What do these 3 lines print?
- 8. Is really equal
- 8-answer.txt: What do these 3 lines print?
- 9. Is really the same
- 9-answer.txt: What do these 3 lines print?
- 10. And with a list, is it equal
- 10-answer.txt: What do these 3 lines print?
- 11. And with a list, is it the same
- 11-answer.txt: What do these 3 lines print?
- 12. And with a list, is it really equal
- 12-answer.txt: What do these 3 lines print?
- 13. And with a list, is it really the same
- 13-answer.txt: What do these 3 lines print?
- 14. List append
- 15. List add
- 15-answer.txt: What does this script print?
- 16. Integer incrementation
- 16-answer.txt: What does this script print?
- 17. List incrementation
- 18. List assignation
- 19. Copy a list object
- 19-copy_list.py: Python function
def copy_list(l):that returns a copy of a list. - 20. Tuple or not?
- 21. Tuple or not?
>>> a = 89
>>> b = 100 >>> a = 89
>>> b = 89 >>> a = 89
>>> b = a + 1 >>> s1 = "Best School"
>>> s2 = s1
>>> print(s1 == s2)>>> s1 = "Best"
>>> s2 = s1
>>> print(s1 is s2)>>> s1 = "Best School"
>>> s2 = "Best School"
>>> print(s1 == s2)>>> s1 = "Best School"
>>> s2 = "Best School"
>>> print(s1 is s2)>>> l1 = [1, 2, 3]
>>> l2 = [1, 2, 3]
>>> print(l1 == l2)>>> l1 = [1, 2, 3]
>>> l2 = [1, 2, 3]
>>> print(l1 is l2)>>> l1 = [1, 2, 3]
>>> l2 = l1
>>> print(l1 == l2)>>> l1 = [1, 2, 3]
>>> l2 = l1
>>> print(l1 is l2)l1 = [1, 2, 3]
l2 = l1
l1.append(4)
print(l2)l1 = [1, 2, 3]
l2 = l1
l1 = l1 + [4]
print(l2)def increment(n):
n += 1
a = 1
increment(a)
print(a)
def increment(n):
n.append(4)
l = [1, 2, 3]
increment(l)
print(l)
def assign_value(n, v):
n = v
l1 = [1, 2, 3]
l2 = [4, 5, 6]
assign_value(l1, l2)
print(l1)
a = ()a = (1, 2)
