Knowee
Questions
Features
Study Tools

What will be the output of the given code?lis_1= [1,2,3]lis_2= [4,5,6]lis_3=[7,8,9]lis_1.append(lis_3)lis_2.extend(lis_3)print(lis_1,lis_2)

Question

What will be the output of the given code?

lis_1= [1,2,3]

lis_2= [4,5,6]

lis_3=[7,8,9]

lis_1.append(lis_3)

lis_2.extend(lis_3)

print(lis_1,lis_2)
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given Python code will be:

[1, 2, 3, [7, 8, 9]] [4, 5, 6, 7, 8, 9]

Here's the step by step explanation:

  1. Three lists are created: lis_1 with elements 1, 2, 3; lis_2 with elements 4, 5, 6; and lis_3 with elements 7, 8, 9.

  2. The append() function is used to add lis_3 to the end of lis_1. This adds the entire list lis_3 as a single element to lis_1, resulting in lis_1 becoming [1, 2, 3, [7, 8, 9]].

  3. The extend() function is used to add the elements of lis_3 to the end of lis_2. This adds each element of lis_3 individually to lis_2, resulting in lis_2 becoming [4, 5, 6, 7, 8, 9].

  4. The print() function is used to print the contents of lis_1 and lis_2, resulting in the output: [1, 2, 3, [7, 8, 9]] [4, 5, 6, 7, 8, 9].

This problem has been solved

Similar Questions

What will be the output of the following Python code?x=[[]]*4x[1].append(7)print(x)

What will be the output of the following Python code?A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B = [[3, 3, 3], [4, 4, 4], [5, 5, 5]] zip(A, B)

l = [1,2,3,4,5,6]l.append([a,b,c,d,e,f,g,h,i,j,k])print(len(l))What will be the output of this code in python

What will the output of the following code be?l = [32, 34, 12, 27, 33]l.append([14, 19])print(len(l))

What is the output of below code snippeta = [ [8, 2] , [4, 1, 2, 2] ]b = a[1][2:]print(b)

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.