Python List Question: Python Programming Questions

Python List Question. MCQs on Lists in Python Programming Language. For more Lists MCQs in Python see Python List MCQs

 

Python List Question

 

 

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

a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]

 

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

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

a) A
b) Daman
c) Error
d) n

 

Which of the following commands will create a list ??

a) list1 = list()
b) list1 = []
c) list1 = list([1, 2, 3])
d) all of the mentioned

 

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

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) [‘celery’, ‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’]

 

Python List Question

 

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

def f(values):
values[0] = 44
v = [1, 2, 3]
f(v)
print(v)

a) [1, 44]
b) [1, 2, 3, 44]
c) [44, 2, 3]
d) [1, 2, 3]

 

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

def example(L):
”’ (list) -> list
”’

i = 0
result = []

while i < len(L):
result.append(L[i])
i = i + 3
return result

a) Return a list containing every third item from L starting at index 0
b) Return an empty list
c) Return a list containing every third index from L starting at index 0
d) Return a list containing the items from L starting from index 0, omitting every third item

 

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

>>>list1 = [1, 3]
>>>list2 = list1
>>>list1[0] = 4
>>>print(list2)

a) [1, 3]
b) [4, 3]
c) [1, 4]
d) [1, 3, 4]

 

What will be the output of the code ??

def increment_items(L, increment):
i = 0
while i < len(L):
L[i] = L[i] + increment
i = i + 1
values = [1, 2, 3]
print(increment_items(values, 2))
print(values)

a) None
[3, 4, 5]

b) None
[1, 2, 3]

c) [3, 4, 5]
[1, 2, 3]

d) [3, 4, 5]
None

 

Python List Question

 

What will be the output of the following Python ??

myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
myList[i – 1] = myList[i]
for i in range(0, 6):
print(myList[i], end = ” “)

a) 2 3 4 5 6 1
b) 6 1 2 3 4 5
c) 2 3 4 5 6 6
d) 1 1 2 3 4 5

 

What will be the output ??

def addItem(listParam):
listParam += [1]
mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))

a) 1
b) 4
c) 5
d) 8

 

What will be the output of the following code ??

myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i]
indexOfMax = i
>>>print(indexOfMax)

a) 1
b) 2
c) 3
d) 4

 

What will be the output of the following ??

list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
print(len(list1 + list2))

a) 2
b) 4
c) 5
d) 8

 

Python List Question

 

What will be the output ??

>>>list(“a#b#c#d”.split(‘#’))

a) [‘a’, ‘b’, ‘c’, ‘d’]
b) [‘a b c d’]
c) [‘a#b#c#d’]
d) [‘abcd’]

 

To which of the following the “in” operator can be used to check if an item is in it ??

a) Lists
b) Dictionary
c) Set
d) All of the mentioned

 

What is the output ??

>>>”Welcome to Python”.split()

a) [“Welcome”, “to”, “Python”]
b) (“Welcome”, “to”, “Python”)
c) {“Welcome”, “to”, “Python”}
d) “Welcome”, “to”, “Python”

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!