@PythonPr Answer: C) [1, 2, 3]
b = a doesnโt copy the list; it points to the same list in memory.
b.append(3) modifies the list in place.
So a also changes.
@PythonPr Answer: B. [1, 2, 3, 4, 5]
Why?
b = a doesnโt create a new list.
It makes b point to the same list in memory as a.
When you do:
b += [4, 5]
+= modifies the list in place.
So the original list changes, and since a and b reference the same object, a reflects the update too.
Wrapping up my OOP notes ๐. Putting it all together with QuizBrain as an example. These projects show how classes, methods, and attributes interact in real code.
Check out the full code on GitHub ๐๐พ
quiz_brain: https://t.co/XoBZzmbAze
#PythonProjects#CodingTips#LearnPython
Continuing with Python OOP: exploring attributes & methods, self, and object behaviors.
These concepts are what make Python powerful for building projects like quizzes and games!
#PythonProgramming#OOP#LearnPython
Starting my Python OOP journey ๐ป; diving into classes, attributes, and the init() method.
Swipe through to see examples and key takeaways from my notes!
#Python#OOP#CodingJourney
@clcoding for i in list gives you a copy of the element (for immutable types like integers, itโs just a copy). Changing "i" does not affect the original list. If you want to actually modify the list:
arr = [1, 2, 3]
for index in range(len(arr)):
arr[index] = arr[index] * 2
print(arr)