PHYTHON - Objective Type Questions(MCQs)& Answers

Sports GK Questions and Answers 2024 (Latest Updated)

Awards & Honours GK Questions 2024 (Latest Updated)

Questions
21 Which of the following statements is used to create an empty set?
A { }
B set()
C [ ].
D ( )

Answer: set()
22 What is the output of the following piece of code when executed in the python shell?

a={1,2,3}

a.intersection_update({2,3,4,5})

a

A {2,3}
B Error, duplicate item present in list
C Error, no method called intersection_update for set data type
D {1,4,5}

Answer: {2,3}
Advertisement
Article and Schedule Quiz Start Test!
DOWNLOAD CURRENT AFFAIRS PDF FROM APP
23 Which of the following lines of code will result in an error?
A s={abs}
B s={4, ‘abc’, (1,2)}
C s={2, 2.2, 3, ‘xyz’}
D s={san}

Answer:s={san}
24 What is the output of the code shown below?

s=set([1, 2, 3])

s.union([4, 5])

s|([4, 5])

A {1, 2, 3, 4, 5}{1, 2, 3, 4, 5}
B Error {1, 2, 3, 4, 5}
C {1, 2, 3, 4, 5} Error
D Error Error

Answer: {1, 2, 3, 4, 5} Error
25 What is the output of the line of code shown below, if s1= {1, 2, 3}?

s1.issubset(s1)

A True
B Error
C No output
D False

Answer: True
26 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))

Answer: t[3] = 45
27

What will be the output?

d = {"john":40, "peter":45}

d["john"]

A 40
B 45
C “john”
D “peter”

Answer: 40
28 What is the output of the following piece of code when executed in Python shell?

a=("Check")*3

a

A (‘Check’,’Check’,’Check’)
B * Operator not valid for tuples
C (‘CheckCheckCheck’)
D Syntax error

Answer: (‘CheckCheckCheck’)
29 Is the following piece of code valid?

a=2,3,4,5

a

A Yes, 2 is printed
B Yes, [2,3,4,5] is printed
C No, too many values to unpack
D Yes, (2,3,4,5) is printed

Answer:Yes, (2,3,4,5) is printed
30 What is the output of the following code?

a,b=6,7

a,b=b,a

a,b

A (6,7)
B Invalid syntax
C (7,6)
D Nothing is printed

Answer: (7,6)
31 Which of the following is a Python tuple?
A [1, 2, 3]
B (1, 2, 3)
C {1, 2, 3}
D {}

Answer: (1, 2, 3)
32 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))

Answer: t[3] = 45
33 What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:3]

A (1, 2)
B (1, 2, 4)
C (2, 4)
D (2, 4, 3)

Answer: (2, 4)
34 What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:-1]

A (1, 2)
B (1, 2, 4)
C (2, 4)
D (2, 4, 3)

Answer: (2, 4)
35 What will be the output of the following Python code?

>>>t = (1, 2, 4, 3, 8, 9)

>>>[t[i] for i in range(0, len(t), 2)]

A [2, 3, 9]
B [1, 2, 4, 3, 8, 9]
C [1, 4, 8]
D (1, 4, 8)

Answer: [1, 4, 8]
36 What will be the output of the following Python code?

d = {"john":40, "peter":45}

d["john"]

A 40
B 45
C “john”
D “peter”

Answer: 40
37 What will be the output of the following Python code?

>>>t = (1, 2)

>>>2 * t

A (1, 2, 1, 2)
B [1, 2, 1, 2]
C (1, 1, 2, 2)
D [1, 1, 2, 2]

Answer:(1, 2, 1, 2)
38 What will be the output of the following Python code?

>>>t1 = (1, 2, 4, 3)

>>>t2 = (1, 2, 3, 4)

>>>t1 < t2

A True
B False
C Error
D None

Answer: False
39 What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

A 1
B 2
C 5
D Error

Answer: Error
40 What will be the output of the following Python code?

numberGames = {}

numberGames[(1,2,4)] = 8

numberGames[(4,2,1)] = 10

numberGames[(1,2)] = 12

sum = 0

for k in numberGames:

sum += numberGames[k]

print len(numberGames) + sum

A 30
B 24
C 33
D 12

Answer: 33

Random GK Questions

Assam Direct Recruitment Test Series

Teacher Eligibility Test

Assam Direct Recruitment Test Series