Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Lists

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

How do you create an empty list in python

a)

[ ]

b)

{ }

c)

( )

2.

How to create a new empty list in python

a)

[ ]

b)

list ( )

c)

list.init( )

d)

create.list ( )

3.

grades = [2.0, 3.0, 4.0]


Which of the following code can be used to iterate over the grades list ?

a)

for grade in grades :

# todo

b)

i = 0

while i < len(grades) :

#todo

i = i + 1

c)

[print ( i ) for i in grades]

d)

for i, grade in enumerate(grades) :

# todo

4.

grades = [2.0, 3.0, 4.0]


How do you get the length of the list above

a)

len(grades)

b)

length(grades)

c)

list.length(grades)

d)

list.len(grades)

5.

a = [ 1, 3, 5 ]

b = [ 7, 9, 11 ]


How do you merge these two lists ?

a)

a + b

b)

a.extend(b)

c)

a.merge(b)

6.

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


numbers [-3]


What is numbers [-3]

a)

8

b)

9

c)

7

7.

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


print ( numbers[-3] == numbers[7])


The output of the program above is

a)

True

b)

False

8.

numbers = [1,3,5,7]


Which of the following code inserts 9 into the list above at index 2

a)

numbers.insert(2,9)

b)

numbers.insert(1,9)

c)

numbers.insert(3,9)

9.

numbers = [1, 2, 3, 4, 5]


Which of the following code changes the element 4 to 9

a)

numbers[3] = 9

b)

numbers[4] = 9

10.

numbers = [1, 2, 3, 4, 5]


print ( numbers.pop() )


The program above prints

a)

5

b)

syntax error

c)

1

d)

[2, 3, 4, 5]

11.

numbers = [1, 2, 3, 4, 5]


Which of the following code removes the element 5 from the list

a)

numbers.pop()

b)

numbers.remove(5)

c)

del(numbers[4])

d)

del(numbers[5])

12.

numbers = [1, 2, 3, 4, 5]


Which of the following code removes all the elements from the list but retains the list

a)

numbers.clear()

b)

del numbers

c)

delete numbers

d)

numbers.del()

13.

Which of the following are examples of lists

a)

person = ["Ajay", 32, 160.5]

b)

person = ["Ajay", "Tech"]

c)

person = [1, 2, 3, 4, 5]

d)

person = {1, 2, 3, 4, 5}

e)

person = (1, 2, 3, 4, 5)

14.

numbers = [1, 4, 2, 6, 3 ]


Which of the following code can sort this list

a)

sorted(numbers)

b)

numbers.sort()

c)

sort(numbers

d)

numbers.sorted()

15.

numbers = [1, 3, 2, 4, 5]


Which of the following code can output a sorted list without actually sorting the original list

a)

sorted(numbers)

b)

numbers.sort()

c)

numbers.sorted()

d)

sort(numbers)

16.

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


Which of the following code gives the following list as the output


[4, 5, 6]

a)

numbers[3:6]

b)

numbers[3,4,5]

c)

numbers[4,5,6]

d)

numbers[4:6]

17.

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


Which of the following code will give you the output as the array below


[1, 3, 5, 7, 9]

a)

numbers[::2]

b)

numbers[:2]

c)

numbers[0:9:2]

d)

numbers[2:0:9]

18.

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


Which of the following code will give the output as below


[7, 8, 9, 10]

a)

numbers[6:]

b)

numbers[7:10]

c)

numbers[7,10]

d)

numbers[7-10]

19.

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


Which of the following code will give the output as


[4, 6, 8]

a)

[numbers[i] for i in [3, 5,7]]

b)

numbers[4,6,8]

c)

numbers[3,5,7]

20.

names = ["Hyderabad", "New Delhi", "New York"]


What gets printed when you say


names[1][-1]

a)

i

b)

d

c)

k

d)

y

21.

What is the output of the output of the code above ?

a)

1700

b)

1200

c)

800

d)

2400

22.

The output of the code above is

a)

Chennai

b)

Hyderabad

c)

New York

d)

New Delhi

23.

What is the output of the program above

a)

Error

b)

-1

c)

0

d)

None

e)

False

24.

What is the output of the code above

a)

City not found

b)

Hyderabad

c)

Nothing prints

25.

What is the output of the code above ?

a)

False

b)

True

c)

None

d)

None of the above

26.

What is the output of the code above

a)

True

b)

False

c)

None

27.

What is the output of the code above

a)

Type Error

b)

20

c)

30

d)

40

28.

What is the output of the code above ?

a)

6

b)

12

c)

9

d)

18

29.

What is the output of the code above

a)

4

b)

2

c)

3

30.

What is the output of the code above

a)

AA-B-CBA-B-CC

b)

A-B-CAA-B-CBA-B-C

c)

AA-B-CBA-B-CC

d)

AA-B-CBA-B-CCA-B-C

31.

What is the output of the code above

a)

['C', 'B', 'A']

b)

['A','B','C']

32.

What is the output of the code above

a)

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

b)

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

c)

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

d)

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

e)

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

33.

What is the output of the code above

a)

[2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8]

b)

[2,4,6,8]

c)

[2,4,6,8,10]

34.

What is the output of the program above

a)

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

b)

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

c)

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

35.

What is the output of the code above

a)

[3, 4]

b)

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

c)

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

d)

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

36.

What is the output of the program above

a)

8

b)

7

c)

4

d)

12

e)

13

37.

What is the output of the code above

a)

6

b)

7

c)

3

d)

12

e)

10

38.

What is the output of the code above

a)

10

b)

20

c)

30

d)

40

39.

what does the code above print

a)

5

4

3

b)

5

4

3

2

1

c)

No output

40.

What is the output of the code above

a)

9

b)

14

c)

15

d)

6

e)

10

41.

What is the output of the program above

a)

10

b)

5

c)

15

42.

The output of the program above is

a)

True

b)

False

43.

The output of the code above is

a)

Equal

b)

unequal

44.

The output of the code above is

a)

[3, 2]

b)

[3, 2,1]

c)

[3]

45.

What is the output of the code above

a)

[1, 2, 3, 4, 5]

b)

[ ]

c)

[5]

d)

[1]

46.

What is the output of the code above

a)

[1, 2, 3, 4, 5]

b)

[ ]

47.

The output of the code above is to print "greater" how many times

a)

2

b)

1

c)

3

d)

5

e)

9

48.

The output of the code above is

a)

1

5

10

15

b)

4

7

11

15

c)

1

4

8

12

d)

4

6

9

12

49.

What is the output of the program above

a)

False

b)

True

c)

Index out of bounds error

50.

What is the output of the code above

a)

Equal

b)

Unequal

c)

Index out of bounds error