wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Sequences-2

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

Suppose list1 is [1, 5, 9], what is sum(list1)?

a)

1

b)

9

c)

15

d)

Error

2.

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]

3.

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)

4.

What will be the output of the following Python code?

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

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

>>> a<b

a)

False

b)

True

c)

Error, < operator is not valid for tuples

d)

Error, < operator is valid for tuples but not if there are sub-tuples

5.

What will be the output of the following Python code?


>>>example = "snow world"

>>>print("%s" % example[4:7])

a)

wo

b)

world

c)

sn

d)

rl

6.

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


>>> print([i+j for i in "abc" for j in "def"])

a)

[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]

b)

[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

c)

[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]

d)

[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

7.

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

8.

If a={5,6,7}, what happens when a.add(5) is executed?

a)

a={5,5,6,7}

b)

a={5,6,7}

c)

Error as there is no add function for set data type

d)

Error as 5 already exists in the set

9.

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)

10.

Which of the following is not a declaration of the dictionary?

a)

{1: ‘A’, 2: ‘B’}

b)

dict([[1,”A”],[2,”B”]])

c)

{1,”A”,2”B”}

d)

{ }