wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

LIST-TUPLES-SET-DICTIONARY

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following commands will create a list?

a)

list1 = list()

b)

list1 = list()

c)

list1 = list([1, 2, 3])

d)

all of the mentioned

2.

What is the output when we execute list(“hello”)?

a)

[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

b)

[‘hello’]

c)

[‘hello’]

d)

None of the Above

3.

To shuffle the list(say list1) what function do we use?

a)

list1.shuffle()

b)

shuffle(list1)

c)

random.shuffle(list1)

d)

random.shuffleList(list1)

4.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

[2, 33, 222, 14]

b)

Error

c)

25

d)

[25, 14, 222, 33, 2]

5.

>>>names = ['Amir', 'Bear', 'Charlton', 'Daman'] >>>print(names[-1][-1])

a)

A

b)

Daman

c)

Error

d)

n

6.

Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?

a)

0

b)

1

c)

4

d)

2

7.

To insert 5 to the third position in list1, we use which command?

a)

list1.insert(3, 5)

b)

list1.insert(2, 5)

c)

list1.add(3, 5)

d)

list1.append(3, 5)

8.

Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3]

what is list1 after listExample.pop()?

a)

[3, 4, 5, 20, 5, 25, 1]

b)

[1, 3, 3, 4, 5, 5, 20, 25]

c)

[3, 5, 20, 5, 25, 1, 3]

d)

[1, 3, 4, 5, 20, 5, 25]

9.

numbers = [1, 2, 3, 4]

numbers.append([5,6,7,8])

print(len(numbers))

a)

4

b)

5

c)

8

d)

12

10.

veggies = ['carrot', 'broccoli', 'potato', 'asparagus'] veggies.insert(veggies.index('broccoli'), 'celery') print(veggies)

a)

[‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’]

b)

[‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]

c)

[‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]

d)

[‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]

11.

What will be the output of the following Python code?

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

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

a)

1

b)

2

c)

5

d)

Error

12.

If a=(1,2,3,4), a[1:-1] is _________

a)

Error, tuple slicing doesn’t exist

b)

[2,3]

c)

(2,3,4)

d)

(2,3)

13.

Is the following Python code valid?

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

>>> b=('A','B','C')

>>> c=tuple(zip(a,b))

a)

Yes, c will be ((1, ‘A’), (2, ‘B’), (3, ‘C’))

b)

Yes, c will be ((1,2,3),(‘A’,’B’,’C’))

c)

No because tuples are immutable

d)

No because the syntax for zip function isn’t valid

14.

Is the following Python code valid?

>>> a,b,c=1,2,3

>>> a,b,c

a)

Yes, [1,2,3] is printed

b)

No, invalid syntax

c)

Yes, (1,2,3) is printed

d)

1 is printed

15.

What will be the output of the following Python code?

>>> a=(1,2)

>>> b=(3,4)

>>> c=a+b

>>> c

a)

(4,6)

b)

(1,2,3,4)

c)

Error as tuples are immutable

d)

None

16.

Which of these about a set is not true?

a)

Mutable data type

b)

Allows duplicate values

c)

Data type with unordered values

d)

Immutable data type

17.

What will be the output of the following Python code?

nums = set([1,1,2,3,3,3,4,4])

print(len(nums))

a)

7

b)

Error

c)

4

d)

8

18.

Which of the following statements is used to create an empty set?

a)

{ }

b)

set( )

c)

[ ]

d)

( )

19.

If a={5,6,7,8}, which of the following statements is false?

a)

print(len(a))

b)

print(min(a))

c)

a.remove(5)

d)

a[2]=45

20.

What will be the output of the following Python code?

>>> a={4,5,6}

>>> b={2,8,6}

>>> a+b

a)

{4,5,6,2,8}

b)

{4,5,6,2,8,6}

c)

Error as unsupported operand type for sets

d)

Error as the duplicate item 6 is present in both sets

21.

What will be the output of the following Python code?

>>> a={4,5,6}

>>> b={2,8,6}

>>> a-b

a)

{4,5}

b)

{6}

c)

Error as unsupported operand type for set data type

d)

Error as the duplicate item 6 is present in both sets

22.

What will be the output of the following Python code?

>>> a={3,4,5}

>>> a.update([1,2,3])

>>> a

a)

Error, no method called update for set data type

b)

{1, 2, 3, 4, 5}

c)

Error, list can’t be added to set

d)

Error, duplicate item present in list

23.

Which of the following statements create a dictionary?

a)

d = {}

b)

d = {“john”:40, “peter”:45}

c)

d = {40:”john”, 45:”peter”}

d)

All of the mentioned

24.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

print(list(d.keys()))

a)

[“john”, “peter”]

b)

[“john”:40, “peter”:45]

c)

(“john”, “peter”)

d)

(“john”:40, “peter”:45)

25.

What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}

for i,j in a.items():

print(i,j,end=" ")

a)

1 A 2 B 3 C

b)

1 2 3

c)

A B C

d)

1:”A” 2:”B” 3:”C”