Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python - List and Tuples

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the output of the following piece of code when executed in Python shell?


>>> a=("Check")*3

>>> a



a)

(‘Check’,’Check’,’Check’)

b)

* Operator not valid for tuples

c)

(‘CheckCheckCheck’)

d)

Syntax error

2.

Is the following piece of code valid?


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

>>> del a

a)

No because tuple is immutable

b)

Yes, the entire tuple is deleted

c)

No, invalid syntax for del method

d)

Yes, first element in the tuple is deleted

3.

What type of data is: a=[(1,1),(2,4),(3,9)]?

a)

Array of tuples

b)

List of tuples

c)

Tuples of lists

d)

Invalid type

4.

Which of the following is true for a tuple?

a)

Tup = 1,2,3

b)

Tup = (""1,"2)

c)

Tup = (1,2,3,4)

d)

None of the above

5.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

6.

Suppose you have the following tuple definition:


t = ('foo', 'bar', 'baz')


Which of the following statements replaces the second element ('bar') with the string 'qux':

a)

t[1] = 'qux'

b)

t(1) = 'qux'

c)

t[1:1] = 'qux'

d)

error

7.

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]

8.

Suppose list=[12,3,22,"mago","hello"], what is list[-6]

a)

Error

b)

None

c)

mango

d)

12

9.

L_names=['Harsh','Amit','Sahil','Viresh']

min(L_names)

a)

'Harsh'

b)

'Amit'

c)

'Viresh'

d)

None of the above

10.

L_names=['Harsh','Amit','Sahil','Viresh']

L_names.pop()

a)

'Harsh'

b)

'Amit'

c)

'Viresh'

d)

None of the above

11.

If L1=[2,4,8,16], L2=[32,64] what is L1+L2

a)

[2,4,8,16,32,64]

b)

[2,4,8,16][32,64]

c)

[2,4,8,16],[32,64]

d)

None of the above

12.

If L1=[2,4,8,16] What is the result of the following statement

16 in L1

a)

True

b)

False

13.

L=[2,4,8,16,32,64] what is L[:2]

a)

[2,4]

b)

[2,4,8]

c)

2,4

d)

None of the above

14.

T=((1,2,3),(3,4))

what is T[1][1]

a)

4

b)

3

c)

2

d)

1

15.

Which function can be used to convert list to a tuple

a)

tuple

b)

list

c)

to_list

d)

to_tuple

16.

Suppose list1 is [1, 3, 2], What is list1 * 2 ?

a)

[2, 6, 4].

b)

[1, 3, 2, 1, 3]

c)

[1, 3, 2, 1, 3, 2]

d)

[1, 3, 2, 3, 2, 1]

17.

To remove string “hello” from list1, we use which command?

a)

list1.remove(“hello”)

b)

list1.remove(hello)

c)

list.remove(“hello”)

d)

list.remove(hello)

18.

Suppose a tuple T is declared as T=(20,36,34,49), which of the following is incorrect?

a)

print(T[3])

b)

T[3] = 49

c)

print(min(T))

d)

print(T.count(20))

19.

Identify the data type of T:


T = [‘A’, ‘23’, ‘92’, ‘(10,20)’]

a)

List

b)

Dictionary

c)

String

d)

Tuple

20.

What is the output of the code?

a = (33, 55)

a.append(22)

print(a)

a)

33 55 22

b)

33

55

22

c)

33, 55, 22

d)

Error