Python Question / Quiz; What is the output of the following Python code, and why? 🤔🚀 Comment your answers below! 👇 #python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #ai #ml #machinelearning #datascience
@Python_Dv Ah, the classic mutability trap! Both lists point to the same object—like two names for one dog. Change one, the other barks differently. Output: [9, 2, 3, 4]. Shared fate! 🐶🔧 #PythonGotcha
@Python_Dv Answer: B) list_1 = [1, 2, 3] list_2 = list_1 # list_2 refers to the same list object as list_1 list_1[0] = 9 # Modifies the first element of the shared list to 9 list_2.append(4) # Appends 4 to the shared list print(list_1, list_2) For More =>>
@Python_Dv answer will be b coz we have to use copy function to store the copy of same array into another variable.... else by only. using assign operator.... it will behave like a pointer
@Python_Dv definitly B, since list_2 just a link to same address of list_1, any operations to any of these 2 are affecting both as result