β˜‘ MCQ PRACTICE

Python Programming Unit 1

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

πŸ“š Python Programming
πŸ“– Unit 1
🎯 MCQs
Python Programming MCQs - Unit 1

Python Programming MCQs - Unit 1

1

Is Python case sensitive when dealing with identifiers?

A yes
B no
C machine dependent
D none of the mentioned
Correct Answer yes
2

Following set of commands are executed in shell, what will be the output?>>>str="hello" >>>str[:2]

A he
B lo
C olleh
D hello
Correct Answer he
3

def example(a): a = a + '2' a = a*2 return a print(example("hello"))

A indentation Error
B cannot perform mathematical operation on strings
C hello2
D hello2hello2
Correct Answer hello2hello2
4

What is the output of the following?x = ['ab', 'cd'] for i in x: i.upper() print(x)

A [β€˜ab’, β€˜cd’].
B [β€˜AB’, β€˜CD’].
C Error
D [None, None].
Correct Answer [β€˜ab’, β€˜cd’].
5

What is the output of the following?i = 2 while True: if i%3 == 0: break print(i) i += 2

A 2 4 6 8 10 …
B 2 4
C 2 3
D Error
Correct Answer 2 4
6

What is the output of the following?x = 'abcd' for i in range(x): print(i)

A a b c d
B 0 1 2 3
C Error
D none of the mentioned
Correct Answer Error
7

What is the output of the following?d = {0: 'a', 1: 'b', 2: 'c'} for i in d: print(i)

A 0 1 2
B a b c
C 0 a 1 b 2 c
D none of the mentioned
Correct Answer 0 1 2
8

What is the output of the following?string = "my name is m" for i in string: print (i, end=", ")

A m, y, , n, a, m, e, , i, s, , m,
B m, y, , n, a, m, e, , i, s, , m
C my, name, is, x,
D Error
Correct Answer m, y, , n, a, m, e, , i, s, , m,
9

What is the output when following code is executed ?>>>print(0xA + 0xB + 0xC)

A 0xA0xB0xC
B Error
C 0x22
D 33
Correct Answer 33
10

What is the output of the following code ?>>>print(max("what are you"))

A Error
B What
C y
D you
Correct Answer y
11

What is the output of the following?print('abcdefcdghcd'.split('cd', -1))

A [β€˜ab’, β€˜ef’, β€˜gh’].
B [β€˜ab’, β€˜ef’, β€˜gh’, ”].
C (β€˜ab’, β€˜ef’, β€˜gh’)
D (β€˜ab’, β€˜ef’, β€˜gh’, ”)
Correct Answer [β€˜ab’, β€˜ef’, β€˜gh’, ”].
12

Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1) ?

A [3, 4, 5, 20, 5, 25, 3].
B [1, 3, 3, 4, 5, 5, 20, 25].
C [3, 5, 20, 5, 25, 1, 3].
D [4, 5, 20, 5, 25, 1, 3].
Correct Answer [3, 5, 20, 5, 25, 1, 3].
13

What is the output when following code is executed ?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
Correct Answer 1
14

What will be the output?def f(i, values = []): values.append(i) return values f(1) f(2) v = f(3) print(v)

A [1] [2] [3].
B [1] [1, 2] [1, 2, 3].
C 1 2 3
D [1, 2, 3].
Correct Answer [1, 2, 3].
15

What is the output of the following piece of code?>>> a=(2,3,1,5) >>> a.sort() >>> print(a)

A (1,2,3,5)
B (5,1,3,2)
C (5,3,2,1)
D Error
Correct Answer Error
16

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

A print(t[3])
B t[3] = 45
C print(max(t))
D print(len(t))
Correct Answer t[3] = 45
17

Which of these about a set is not true?

A Mutable data type
B Allows duplicate values
C Data type with unordered values
D Immutable data type
Correct Answer Immutable data type
18

What is the output of the following code?nums = set([1,1,2,3,3,3,4,4]) print(len(nums))

A 8
B Error, invalid syntax for formation of set
C 4
D 8
Correct Answer 4
19

What is the output of the following piece of code?>>> a={3,4,5} >>> a.update([1,2,3]) >>> print(a)

A Error, no method called update for set data type
B {1, 2, 3, 4, 5}
C Error, list can’t be added to set
D Error, duplicate item present in list
Correct Answer {1, 2, 3, 4, 5}
20

Set makes use of __________ and Dictionary makes use of ____________ ?

A keys, key values
B keys, keys
C key values, keys
D key values, key values
Correct Answer keys, key values
21

What is the output of the code shown below?l=[1, 2, 4, 5, 2, 'xy', 4] print(set(l)) print(l)

A {1, 2, 4, 5, 2, β€˜xy’, 4} [1, 2, 4, 5, 2, β€˜xy’, 4]
B {1, 2, 4, 5, β€˜xy’} [1, 2, 4, 5, 2, β€˜xy’, 4]
C {1, 5, β€˜xy’} [1, 5, β€˜xy’]
D {1, 2, 4, 5, β€˜xy’} [1, 2, 4, 5, β€˜xy’]
Correct Answer {1, 2, 4, 5, β€˜xy’} [1, 2, 4, 5, 2, β€˜xy’, 4]
22

Suppose d = {β€œmadhu”:521, β€œnaveen”:532}, what happens when we try to retrieve a value using the expression d[β€œsuresh”]?

A Since β€œsuresh” is not a value in the set, Python raises a KeyError exception
B It is executed fine and no exception is raised, and it returns None
C Since β€œsuresh” is not a key in the set, Python raises a KeyError exception
D Since β€œsusan” is not a key in the set, Python raises a syntax error
Correct Answer Since β€œsuresh” is not a key in the set, Python raises a KeyError exception
23

Which of these about a dictionary is false?

A The values of a dictionary can be accessed using keys
B The keys of a dictionary can be accessed using values
C Dictionaries aren’t ordered
D Dictionaries are mutable
Correct Answer The keys of a dictionary can be accessed using values
24

What is the output of the following code?a={1:"A",2:"B",3:"C"} for i,j in a.items(): print(i,j,end=" ")

A 1 A 2 B 3 C
B 1 2 3
C 1:”A” 2:”B” 3:”C”
D A B C
Correct Answer 1 A 2 B 3 C
25

What is the output of the following?x = (i for i in range(3)) for i in x: print(i) for i in x: print(i)

A 0 1 2
B error
C 0 1 2 0 1 2
D none of the mentioned
Correct Answer 0 1 2
← Back to All MCQs