Python MCQ's
Q1. Suppose list1 = [1, 2, 3] what is list1 * 2.
Ans: [1, 2, 3, 1, 2, 3]
Q2. What is the output of the following?
string = "My name is x"
for i in string.split():
print(i, end=",")
Ans: My,name,is,x,
Q3: What is the output of the following code?
a = {1:5,2:3,3:4}
a.pop(3)
print(a)
Ans: {1: 5, 2: 3}
Q4: Which of the following will create list?
a. all of the options
b. list1 = list([1,2,3])
c. list1 = list()
d. list1 = []
Ans: a
Q5. What is the output of the following snippet of code?
numbers = {}
letters = {}
comb = {}
numbers[1] = 45
numbers[3] = 32
letters[4] = "b"
comb["Numbers"] = numbers
comb["letters"] = letters
print(comb)
Ans:{'Numbers': {1: 45, 3: 32}, 'letters': {4: 'b'}}
0 Comments