Python Question / Quiz; What is the output of the following Python code, and why? 🤔🚀 Comment your answers below! 👇 #python #programming #developer #morioh #programmer #coding #coder #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #machinelearning

Python_Dv's tweet image. Python Question / Quiz;

What is the output of the following Python code, and why? 🤔🚀 Comment your answers below! 👇

#python #programming #developer #morioh #programmer #coding #coder #webdeveloper #webdevelopment #pythonprogramming #pythonquiz #machinelearning

Here’s what each line does: 1. `a = [1, 2, 3]` initializes list `a` with three elements: 1, 2, and 3. 2. `b = [4, 5]` initializes list `b` with two elements: 4 and 5. 3. `a.extend(b)` extends list `a` by appending all elements from list `b` to it. After this operation, list `a`…


a = [1, 2 ,3] # a <- [1, 2 ,3] b = [4, 5] # b <- [4, 5] a.extend(b) # a <- [1, 2, 3, 4, 5] len(a) # 5 <- len(a) Answer: c) 5


Here extend will add 2 elements So the answer is 5 elements


a.extend(b) The extend method is used to add elements from one list (b) to the end of another list (a). print(len(a)) 'a'. len() function returns the number of items in an object, Given input: 1. a=[1,2,3] 2. b=[4,5] 3. a.extend(b) 4. print(len(a)) The correct answer is: b) 4


C. 5 is the output. Explanation: 1. The extend() method appends the elements of list b to list a. 2. After extending, a becomes [1, 2, 3, 4, 5]. 3. The len(a) returns the length of the modified list, which is 5.


# c) 5 Reason: Line 3: The extend() method adds the specified list elements to the end of the current list. Line 4: The len() function returns the number of items in list - a = [1, 2, 3, 4, 5]. Output: 5


There is answer is 5 a starts as [1, 2, 3]. b is [4, 5]. a.extend(b) appends elements from b to a, making a equal to [1, 2, 3, 4, 5]. print(len(a)) prints the length of a, which is 5.


answer "b" will be when you use insert against extend


5. After a.extend(b) => a = [1,2,3,4,5] => len(a) => 5


United States Trends
Loading...

Something went wrong.


Something went wrong.