wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Lists: Introduction and Basic Creation

Total questions: 84

Worksheet time: 42mins

Name
Class
Date
1.

Which statement best defines a Python list as introduced in this section?

a)

A fixed-size container that cannot change once created

b)

An ordered, changeable collection that allows duplicate members

c)

An unordered collection of unique items only

d)

A data type used only for numeric values

2.

Which of the following directly demonstrates list mutability as described?

a)

Lists are created using parentheses

b)

Lists can grow and shrink as needed

c)

Lists cannot contain duplicate items

d)

Lists are not a sequence type

3.

What syntax is used to declare a list with initial values according to the example?

a)

Curly braces with semicolons between values

b)

Parentheses with spaces between values

c)

Square brackets with values separated by commas

d)

Angle brackets with colon-separated values

4.

In the example list1 = [1,2,3,'A','B',7,8,[10,11]], what concept does the inner [10,11] illustrate?

a)

Tuple conversion

b)

List immutability

c)

Nested list

d)

Set membership

5.

Which Python list operation is demonstrated by the expression [1, 2, 3] + [4, 5, 6] producing [1, 2, 3, 4, 5, 6]?

a)

Length

b)

Concatenation

c)

Repetition

d)

Membership

6.

In the table of basic list operations, what does the expression 3 in [1, 2, 3] evaluate to?

a)

False

b)

True

c)

3

d)

[3]

7.

Given L = ['mrcet', 'college', 'MRCET!'], what does L[2] return?

a)

'mrcet'

b)

'college'

c)

'MRCET!'

d)

IndexError

8.

Which statement best describes list indexing based on the example L[2] -> MRCET! ?

a)

Offsets start at one

b)

Offsets start at zero

c)

Negative indexes are not allowed

d)

Indexes must be even numbers

9.

Which operation is shown by the code for x in [1, 2, 3]: print x producing 1 2 3?

a)

Membership

b)

Iteration

c)

Concatenation

d)

Slicing

10.

What does a negative index like L[-2] refer to in Python lists?

a)

The second element from the left

b)

The last element

c)

The second element from the right

d)

An invalid position

11.

If list1 = [1,2,3,4,5,6,7,8,9,10], what is the result of list1[:1]?

a)

[1]

b)

[2]

c)

[1, 2]

d)

[]

12.

You have x = [1, 2, 4, 6, 7]. Which call inserts the value 3 at index 2 to obtain [1, 2, 3, 4, 6, 7]?

a)

x.insert(2, 3)

b)

x.insert(3, 2)

c)

x.append(3)

d)

x.extend([3])

13.

Starting with x = [5, 3, 8, 6], which code deletes the element at index 1 so x becomes [5, 8, 6]?

a)

del x(1)

b)

x.remove(1)

c)

del x[1]

d)

x.pop(1.0)

14.

Given x = [1, 2, 10, 4, 6, 7], what does x.pop() return?

a)

[1, 2, 10, 4, 6]

b)

7

c)

6

d)

[1, 2, 10, 4, 6, 7]

15.

After executing x = [1, 2, 10, 4, 6, 7]; x.pop(), what is the value of x?

a)

[1, 2, 10, 4, 6]

b)

[1, 2, 10, 4, 6, 7]

c)

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

d)

[1, 2, 4, 6]

16.

What item is removed and returned by x.pop(2) when x = [1, 2, 10, 4, 6]?

a)

1

b)

2

c)

10

d)

4

17.

After running x = [1, 33, 2, 10, 4, 6]; x.remove(33), what is x?

a)

[1, 33, 2, 10, 4, 6]

b)

[1, 2, 10, 4, 6]

c)

[33, 2, 10, 4, 6]

d)

[1, 2, 4, 6]

18.

Which statement best describes remove()?

a)

Removes by index and returns the element

b)

Removes the specified item value from the list

c)

Reverses the list in place

d)

Sorts the list in descending order

19.

Which method reverses the order of elements in a list in place?

a)

reverse()

b)

reversed()

c)

invert()

d)

flip()

20.

If x = [1, 2, 3, 4, 5, 6, 7] and x.reverse() is executed, what is x afterward?

a)

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

b)

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

c)

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

d)

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

21.

What does sort() do to a list of numbers by default?

a)

Sorts in descending order

b)

Sorts in ascending order

c)

Randomizes the order

d)

Removes duplicates then sorts

22.

Given x = [7, 6, 5, 4, 3, 2, 1]; x.sort(); what is x?

a)

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

b)

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

c)

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

d)

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

23.

For x = [10, 1, 5, 3, 8, 7], what is the result after x.sort()?

a)

[10, 1, 5, 3, 8, 7]

b)

[1, 3, 5, 7, 8, 10]

c)

[10, 8, 7, 5, 3, 1]

d)

[1, 5, 3, 7, 8, 10]

24.

In Python, which function is commonly used with a for loop to iterate over list indices?

a)

range()

b)

map()

c)

input()

d)

print()

25.

Which statement best defines a mutable object in Python?

a)

An object that cannot be changed after creation

b)

An object that can be changed after it is created

c)

An object that is always numeric

d)

An object stored in read-only memory

26.

Given x = [1,5,8,4], what is x after executing x.append(10)?

a)

[1,5,8,4]

b)

[1,5,8,4,10]

c)

[10,1,5,8,4]

d)

[1,5,8,4,[10]]

27.

Given a = [81, 82, 83]; b = a; b[0] = 5; what is printed by print(a)?

a)

[81, 82, 83]

b)

[5, 82, 83]

c)

[81, 5, 83]

d)

Raises an error

28.

Which option correctly shows a conditional list comprehension that keeps z**2 only when z > 4 for z in range(10)?

a)

[z**2 for z in range(10) if z > 4]

b)

[z**2 if z > 4 for z in range(10)]

c)

[for z in range(10) if z > 4: z**2]

d)

list(map(lambda z: z**2 if z > 4, range(10)))

29.

Which output matches the list comprehension [x**2 for x in range(1, 11) if x % 2 == 1]?

a)

[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

b)

[1, 9, 25, 49, 81]

c)

[2, 4, 6, 8, 10]

d)

[1, 3, 5, 7, 9]

30.

Which statement best describes a list comprehension in Python?

a)

A way to declare immutable sequences using parentheses

b)

A concise way to create new lists by applying an expression to items in an iterable and optionally filtering them

c)

A function that sorts a list in place

d)

A special loop that can only be used with numbers

31.

Which statement best defines a Python tuple?

a)

An unordered, changeable collection written with square brackets

b)

An ordered, unchangeable collection written with round brackets

c)

An ordered, changeable collection written with curly braces

d)

An unordered, unchangeable collection written with angle brackets

32.

Which property of tuples is highlighted as a reason to use them when list contents should not change?

a)

Tuples are sortable by default

b)

Tuples are immutable

c)

Tuples automatically remove duplicates

d)

Tuples support arithmetic operations

33.

According to the material, which statement about tuple efficiency is correct?

a)

Tuples are less efficient than lists due to Python’s implementation

b)

Tuples and lists have identical efficiency in all cases

c)

Tuples are more efficient than lists due to Python’s implementation

d)

Efficiency is not discussed for tuples

34.

Which of the following is NOT a shown way to construct a tuple in the material?

a)

x = ()

b)

x = (1,2,3)

c)

x = tuple(list1)

d)

x = {1,2,3}

35.

Given x = [4, 5, 66, 9], what is the result of y = tuple(x) followed by printing y?

a)

[4, 5, 66, 9]

b)

(4, 5, 66, 9)

c)

(4; 5; 66; 9)

d)

{4, 5, 66, 9}

36.

Which output is shown when creating an empty tuple using x = () and then printing x?

a)

None

b)

[]

c)

()

d)

{}

37.

Which of the following lists includes only operations mentioned as applicable to tuples in the material?

a)

Access items, change items, loop, count, index, length

b)

Append, pop, sort, reverse

c)

Insert, remove, extend, clear

d)

Map, filter, reduce

38.

Tuples support all operations for sequences, but which nuance is noted about their elements?

a)

Elements must all be numbers

b)

Elements cannot be accessed by index

c)

Member objects may be mutable

d)

Elements are automatically sorted

39.

What will be printed by the code: x=('a','b','c','g'); print(x[2])

a)

a

b)

b

c)

c

d)

g

40.

Given x=(2,5,7,'4',8). What happens if we run x[1]=10?

a)

The tuple becomes (2,10,7,'4',8)

b)

A ValueError is raised

c)

A TypeError stating tuple does not support item assignment is raised

d)

Nothing happens; Python ignores it

41.

Consider x=(4,5,6,7,2,'aa'). What will a for i in x: print(i) loop output last?

a)

2

b)

'aa'

c)

7

d)

6

42.

For x=(1,2,3,4,5,6,2,10,2,11,12,2), what is x.count(2)?

a)

2

b)

3

c)

4

d)

5

43.

For x=(1,2,3,4,5,6,2,10,2,11,12,2), what does x.index(2) return?

a)

0

b)

1

c)

6

d)

8

44.

What is the length of x=(1,2,3,4,5,6,2,10,2,11,12,2) using len(x)?

a)

10

b)

11

c)

12

d)

13

45.

Which statement best describes tuple assignment as shown?

a)

It allows changing elements of a tuple in place

b)

It enables assigning more than one variable at a time using tuple structure

c)

It converts a tuple to a list automatically

d)

It only works for numeric tuples

46.

Given tup1=('mrcret','eng college','2004','cse','it','csit') and tup2=(1,2,3,4,5,6,7), what is the result of print(tup1[0]) and print(tup2[1:4]) respectively?

a)

'mrcret' and (2,3,4)

b)

'eng college' and (1,2,3)

c)

'mrcret' and (1,2,3)

d)

'csit' and (3,4,5)

47.

In Python, what is the best description of a tuple as presented?

a)

A mutable sequence created only with parentheses

b)

An immutable comma-separated sequence of items, created with or without parentheses

c)

A dictionary of key-value pairs

d)

A list that can only store numbers

48.

Consider the function: def fun(): str = "mrce t college"; x = 20; return str, x. When called as str, x = fun(), what will print(str); print(x) output?

a)

mrce t college then 20

b)

20 then mrce t college

c)

('mrce t college', 20) on one line

d)

An error because two values cannot be returned

49.

The function circleInfo(r) computes c = 2 * 3.14159 * r and a = 3.14159 * r * r and returns (c, a). What is the printed result of print(circleInfo(10)) as shown?

a)

(31.4159, 314.159)

b)

(62.8318, 314.159)

c)

(62.8318, 628.318)

d)

(20, 200)

50.

What does a tuple comprehension like x = (i for i in 'abc') actually produce according to the material?

a)

A tuple ('a','b','c')

b)

A list ['a','b','c']

c)

A special generator object that can be iterated once

d)

A string 'abc'

51.

Given x = (i for i in 'abc'), what happens when you run: for i in x: print(i)?

a)

It raises a TypeError because x is not iterable

b)

It prints a, b, c on separate lines by iterating once over the generator

c)

It prints ('a', 'b', 'c')

d)

It prints nothing because generators are empty

52.

Which statement about generators from tuple comprehensions is correct based on the text?

a)

They can be iterated multiple times without re-creation

b)

They must always be converted to lists before use

c)

They can be iterated, but only once

d)

They store all produced values in memory at creation

53.

What is the value of z after executing z = [(x, x**2) for x in range(6)] as shown?

a)

[(1, 1), (2, 4), (3, 9), (4, 16), (5, 25), (6, 36)]

b)

[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]

c)

[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]

d)

[(0, 0), (2, 4), (4, 16)]

54.

Which code snippet demonstrates a set comprehension that filters characters not in 'abc' from the string 'abracadabra'?

a)

{x for x in 'abracadabra' if x not in 'abc'}

b)

[x for x in 'abracadabra' if x not in 'abc']

c)

(x for x in 'abracadabra' if x not in 'abc')

d)

set('abracadabra') - set('abc')

55.

What is the result of the set comprehension {3*x for x in range(10) if x > 5}?

a)

{18, 21, 24, 27, 30}

b)

{24, 18, 27, 21}

c)

{15, 18, 21, 24, 27}

d)

{6, 9, 12, 15, 18}

56.

Which statement best defines a Python dictionary as introduced here?

a)

An ordered, immutable collection of values

b)

An unordered, changeable, and indexed collection of key-value pairs written with curly brackets

c)

A sequence of values accessed by integer positions only

d)

A collection that allows duplicate keys but not duplicate values

57.

Which of the following is a valid way to construct the dictionary with keys 1, 2, 3 mapping to 'A', 'B', 'c' respectively?

a)

X=[1:'A',2:'B',3:'c']

b)

X={(1,'A'),(2,'B'),(3,'c')}

c)

X={1:'A',2:'B',3:'c'}

d)

X=dict(['A', 'B', 'c'])

58.

Given dict1 = {"brand":"mrcet","model":"college","year":2004}, which method would remove all items from dict1 according to the table shown?

a)

remove()

b)

clear()

c)

delete()

d)

empty()

59.

Which dictionary method returns a shallow copy of the dictionary?

a)

copy()

b)

fromkeys()

c)

items()

d)

update()

60.

What does fromkeys(seq, v) return?

a)

A list of keys from seq

b)

A new dictionary with keys from seq and values equal to v

c)

A tuple of (key, value) pairs

d)

A shallow copy of an existing dictionary

61.

Which method safely retrieves the value for a key and returns a default if the key does not exist?

a)

keys()

b)

get(key, d)

c)

pop(key)

d)

values()

62.

What does items() return according to the material?

a)

A list of keys

b)

A list of values

c)

A new view of the dictionary's items (key, value)

d)

A shallow copy of the dictionary

63.

If you want a new view of the dictionary's keys, which method should you use?

a)

values()

b)

items()

c)

keys()

d)

setdefault()

64.

Which statement best describes values()?

a)

Returns a new view of the dictionary's values

b)

Returns the value for a key or inserts it

c)

Removes and returns an arbitrary (key, value)

d)

Updates the dictionary with pairs from another

65.

Given dict1 = {"brand":"mrcet","model":"college","year":2004}, what does dict1["brand"] return?

a)

"brand"

b)

"mrcet"

c)

("brand","mrcet")

d)

None

66.

Using the same dict1, which expression returns dict_keys(['brand','model','year'])?

a)

dict1.items()

b)

dict1.keys()

c)

dict1.values()

d)

dict1.copy()

67.

For dict1 as defined, which output matches dict1.items()?

a)

dict_items([('brand','mrcet'),('model','college'),('year',2004)])

b)

dict_items(['brand','model','year'])

c)

dict_items(['mrcet','college',2004])

d)

dict_items('brand','mrcet')

68.

Which loop prints mrcet, college, 2004 on separate lines for dict1?

a)

for items in dict1.keys(): print(items)

b)

for items in dict1.values(): print(items)

c)

for i in dict1.items(): print(i[0])

d)

for k,v in dict1.items(): print(k)

69.

What is the correct way to change the value of key 'year' to 2005 in the dictionary dict1 = {'brand':'mrcet','model':'college','year':2004}?

a)

dict1.update('year':2005)

b)

dict1['year']=2005

c)

dict1.change('year',2005)

d)

update(dict1,'year',2005)

70.

Given dict1 = {'brand':'mrcet','model':'college','year':2004}, what does dict1.pop('model') return?

a)

'college'

b)

'model'

c)

{'model':'college'}

d)

None

71.

After executing dict1 = {'brand':'mrcet','model':'college','year':2004}; dict1.pop('model'), what is a correct resulting dictionary?

a)

{'brand':'mrcet','year':2005}

b)

{'brand':'mrcet','model':'college'}

c)

{'brand':'mrcet','year':2004}

d)

{'model':'college','year':2004}

72.

Which statement removes the key 5 from the dictionary x = {1:1, 2:4, 3:9, 4:16, 5:25}?

a)

x.remove(5)

b)

del x[5]

c)

x.popitem(5)

d)

x.delete(5)

73.

What is the output of y after y = len(x) where x = {1:1, 2:4, 3:9, 4:16}?

a)

3

b)

4

c)

5

d)

16

74.

Consider x = {1:1, 2:4, 3:9, 4:16, 5:25}. What does the loop for key in x: print(key, x[key]) print?

a)

Each key only

b)

Each value only

c)

Each key followed by its value

d)

Key-value pairs as tuples only

75.

Which loop correctly iterates over both keys and values directly as a pair from dictionary x?

a)

for k in x: print(k)

b)

for v in x.values(): print(v)

c)

for k,v in x.items(): print(k,v)

d)

for item in x.keys(): print(item, x.items())

76.

Given customers = [{'uid':1,'name':'John'},{'uid':2,'name':'Smith'},{'uid':3,'name':'Andersson'}], what does the loop for x in customers: print(x['uid'], x['name']) output first?

a)

John 1

b)

1 John

c)

uid name

d)

{'uid':1,'name':'John'}

77.

To change the name of the second customer from 'Smith' to 'charlie' in the list customers, which statement is used?

a)

customers['uid'][2]['name']='charlie'

b)

customers[2]['name']='charlie'

c)

customers[1]['name']='charlie'

d)

customers.pop(1)['name']='charlie'

78.

Which statement adds a new field 'password' with value '123456' to every dictionary in customers during iteration?

a)

for x in customers: x.add('password','123456')

b)

for x in customers: x['password']='123456'

c)

customers['password']='123456'

d)

customers.append({'password':'123456'})

79.

Given the list named customers as shown: [{'uid': 1, 'name': 'John', 'password': '123456'}, {'uid': 2, 'name': 'Smith', 'password': '123456'}, {'uid': 3, 'name': 'charlie', 'password': '123456'}], which Python statement removes the second dictionary (index 1) from the list?

a)

del customers['uid']

b)

del customers[1]

c)

del customers(1)

d)

customers.remove(1)

80.

After executing del customers[1] twice on the original customers list of three dictionaries, what will print(customers) output?

a)

[{'uid': 1, 'name': 'John', 'password': '123456'}]

b)

[{'uid': 1, 'name': 'John', 'password': '123456'}, {'uid': 3, 'name': 'charlie', 'password': '123456'}]

c)

[]

d)

An IndexError is printed instead of a list

81.

To delete only the 'uid' field from every dictionary in the customers list, which loop matches the example shown?

a)

for x in customers: del x['uid']

b)

for x in customers: del customers['uid']

c)

for x in range(len(customers)): del 'uid'

d)

for x in customers: x = del['uid']

82.

After running the loop that deletes x['uid'] for each x in customers, what does x evaluate to in the example?

a)

{'uid': 1, 'name': 'John', 'password': '123456'}

b)

{'name': 'John', 'password': '123456'}

c)

{'uid': 3, 'name': 'charlie', 'password': '123456'}

d)

'uid'

83.

What is the resulting dictionary from the comprehension z = {x: x**2 for x in (2,4,6)}?

a)

{2: 2, 4: 4, 6: 6}

b)

{2: 4, 4: 16, 6: 36}

c)

{4: 2, 16: 4, 36: 6}

d)

{2: 8, 4: 64, 6: 216}

84.

Consider dict11 = {x: x*x for x in range(6)}. Which key–value pair is included?

a)

(6, 36)

b)

(5, 5)

c)

(4, 16)

d)

(1, 0)