Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
23
15
98
Replies
@PythonPr Right, so that's a nice one, Python! The output will depend on the code, but the 'why' is always the key, you know?
0
0
1
@PythonPr The output is B). [1, 2, 3, 4] In Python, when a list is assigned to a new variable using the equals sign (y = x), it does not create a new copy of the list. Instead, both variables become references to the exact same list object in memory. This is known as aliasing.
1
0
22
@PythonPr And: B Reason: append is used to add an element to the end of an existing list, so it just adds 4 to the already existing list of x
0
0
3