0% found this document useful (0 votes)
144 views2 pages

1 What Will Be The Output of Following Code

This document contains a worksheet on list manipulation in Python with 10 problems and their answers. The problems cover list operations like indexing, slicing, concatenation, length, membership testing, list comprehension, and for loops. Key operations include multiplying a list, splitting a string, converting case, accessing nested lists, adding lists, removing items, explaining list comprehension, and printing items in a for loop.

Uploaded by

Muthumeenatchi U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views2 pages

1 What Will Be The Output of Following Code

This document contains a worksheet on list manipulation in Python with 10 problems and their answers. The problems cover list operations like indexing, slicing, concatenation, length, membership testing, list comprehension, and for loops. Key operations include multiplying a list, splitting a string, converting case, accessing nested lists, adding lists, removing items, explaining list comprehension, and printing items in a for loop.

Uploaded by

Muthumeenatchi U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

WORKSHEET – LIST MANIPULATION

1 What will be the output of following code-


list1=[1, 3, 2]
list1 * 2

Ans:

2 What will be the output of following code-


l="Welcome to Python".split()
l

Ans:

3 What will be the output of following code-


print([i.lower() for i in "HELLO"])

Ans:

4 What will be the output of following code-


a=[[[1,2],[3,4],5],[6,7]]
a[0][1][1]

Ans:

5 What will be the output of following code-


a,b=[3,1,2],[5,4,6]
a+b

Ans:

6 What will be the output of following program:


a=[2,1,3,5,2,4]
a.remove(2)
a
Ans:

1|Page
7 Explain List Comprehension and Elegant way to create new List:

Ans:

1. List comprehension is an elegant and concise way to create new list from an
existing list in Python.
2. List comprehension consists of an expression followed by for statement inside
square brackets.
3. Here is an example to make a list with each item being increasing power of 2.

pow2 = [2 ** x for x in range(10)]

# Output: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]


print(pow2)

This code is equivalent to:

pow2 = []
for x in range(10):
pow2.append(2 ** x)

8 What will be the output of following program:


theList=[1, 2, [1.1, 2.2]]
len(theList)

Ans:

9 What will be the output of following program:


my_list = ['p', 'r', 'o', 'b', 'l', 'e', 'm']

print('p' in my_list)

print('a' in my_list)

print('c' not in my_list)

Ans:

10 What will be the output of following program:


for fruit in ['apple','banana','mango']:
print("I like",fruit)

Ans:

2|Page

You might also like