wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Understanding the concept of list

Total questions: 25

Worksheet time: 20mins

Name
Class
Date
1.

What will be the output of the following Python code?


>>> a=(1,2,3,4)

>>> del(a[2])

a)

Now, a=(1,2,4)

b)

Now, a=(1,3,4)

c)

Now a=(3,4)

d)

Error as tuple is immutable

2.

Choose the correct way to access value 20 from the following tuple
tuple1= ("Orange", [10, 20, 30], (5, 15, 25))

a)

tuple1[1:2](1)

b)

tuple1[1:2][1]

c)

tuple1[1][1]

d)

All of the above

3.

Predict the output:

a)

1

2

[13, 18, 11, 16, 13, 18, 13, 2]

b)

0

2

[13, 18, 11, 16, 13, 18, 13, 3]

c)

5

2

[13, 18, 11, 16, 13, 18, 13, 3]

d)

1

2

[13, 18, 11, 16, 13, 18, 13, 3]

4.

What will the following code result in?

a)

True

[9, 7, 5, 3, 1]

b)

False

[9, 7, 5, 3, 1]

c)

True

[1, 3, 5, 7, 9]

d)

None of the above

5.

Out of the following, what is correct syntax to copy one list into another?

a)

listA=listB[]

b)

listA=listB[:]

c)

listA=listB[]()

d)

listA=list(listB)

6.

What gets printed?

a)

H

b)

a

c)

Hasan

d)

Dia

7.

What will be the output of following Python code?

a)

(15,11,16,12)

b)

(15,11,17,16)

c)

(15,11,17,16,12)

d)

Error

8.

Carefully read the given code fragments and figure out the errors that the code may produce.

a)

t5=t3*(3)

b)

t4=t3*3

c)

t3=(6,7)

d)

t6=t3*(3,)

9.

Predict the output :-

a)

3

2

False

3

2

b)

2

2

False

3

3

c)

3

3

False

2

2

d)

2

3

False

2

3

10.

Find the output generated by the code fragment :

plane=("Passengers","Luggage")

plane[1]="Snakes"

a)

plane=("Passengers","Snakes")

b)

plane=("Passengers","Snakes","Luggage")

c)

plane=("Snakes","Passengers","Luggage")

d)

Error

11.

What is the output of the following code?

a)

[0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48]

b)

[4, 8, 16, 20, 28, 32, 40, 44]

c)

[0, 12, 24, 36, 48]

d)

None of the above

12.

Find the error :

L1=[1,11,21,31]

An=L1.remove(41)

a)

(a) Value error : 41 not in list

b)

(b) remove() doesn't return any value

c)

(c) remove() function is not applicable on lists

d)

(d) both (a) & (b)

13.

Given a list L1=[3,4.5,12,25.7,[2,1,0,5],88], which function can change the list to [3,4.5,12,25.7,88]?

a)

del L1[4]

b)

L1.pop(4)

c)

L1.pop(-2)

d)

All the above

14.

Write the output of the following code:

>>> L=[“Amit”,”Anita”,”Zee”,”Longest Word”,123]

>>> print(max(L))

a)

Longest Word

b)

Zee

c)

Amit

d)

Error

15.

What is the output of the following list operation

aList = [10, 20, 30, 40, 50, 60, 70, 80]

print(aList[2:5])

print(aList[:4])

print(aList[3:])

a)

[20, 30, 40, 50]

[10, 20, 30, 40]

[30, 40, 50, 60, 70, 80]

b)

[30, 40, 50]

[10, 20, 30, 40]

[40, 50, 60, 70, 80]

c)

None of these

16.
What output will this code produce?
a)
red
b)
['blue', 'green', 'red']
c)
['red', 'green', 'blue']
d)
error
17.

If list=[17,23,41,10] then list.append(32) will result

a)

[32,17,23,41,10]

b)

[17,23,41,10,32]

c)

[10,17,23,32,41]

d)

[41,32,23,17,10]

18.

Which of the following are true of Python lists?

a)

A list may contain any type of object except another list

b)

A given object may appear in a list more than once

c)

All elements in a list must be of the same type

d)

These represent the same list:

['a', 'b', 'c']

['c', 'a', 'b']

e)

There is no conceptual limit to the size of a list

19.

List a is defined as follows:


a = ['a', 'b', 'c']


Which of the following statements adds 'd' and 'e' to the end of a, so that it then equals ['a', 'b', 'c', 'd', 'e']:

a)

a += ['d', 'e']

b)

a[-1:] = ['d', 'e']

c)

a += 'de'

d)

a.append(['d', 'e'])

e)

a[len(a):] = ['d', 'e']

20.

You have a list a defined as follows:


a = [1, 2, 7, 8]


Write a Python statement using slice assignment that will fill in the missing values so that a equals [1, 2, 3, 4, 5, 6, 7, 8].

a)

a[2:2] = [3, 4, 5, 6]

b)

a[1:2] = [3, 4, 5, 6]

c)

a[2:3] = [3, 4, 5, 6]

d)

a[3:5] = [3, 4, 5, 6]

21.

Consider this assignment statement:


a, b, c = (1, 2, 3, 4, 5, 6, 7, 8, 9)[1::3]


Following execution of this statement, what is the value of b:

a)

5

b)

4

c)

3

d)

6

e)

7

22.

Q-2. The code below manipulates a Python list using the slicing operator. What will be the output?

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

a[::2]=10,20,30,40,50,60

print(a)

a)

ValueError: Attempt to assign a sequence of size 6 to an extended slice of size 5

b)

[10, 2, 20, 4, 30, 6, 40, 8, 50, 60]

c)

[1, 2, 10, 20, 30, 40, 50, 60]

d)

[1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]

23.

The code below uses a Python list and iterates using the range() function. What will be the output?

arr = [1, 2, 3, 4, 5, 6]

for i in range(1, 6):

arr[i - 1] = arr[i]

for i in range(0, 6):

print(arr[i], end = " ")

a)

1 2 3 4 5 6

b)

2 3 4 5 6 1

c)

1 1 2 3 4 5

d)

2 3 4 5 6 6

24.

Which of the following statements would create a tuple in python?

a)

mytuple = ("apple", "banana", "cherry")

b)

mytuple[123] = ("apple", "banana", "cherry")

c)

mytuple = ("2" * ("apple", "banana", "cherry"))

d)

None of the these

25.

What will be the output of the following Python code?

>>> str1 = 'hello'

>>> str2 = ','

>>> str3 = 'world'

>>> str1[-1:]

a)

olleh

b)

hello

c)

h

d)

o