Python Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to Python. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - What is the output for −

'you are doing well' [2:999]

A - 'you are doing well'

B - ' '

C - Index error.

D - 'u are doing well'

Answer : D

Explanation

Slicing will never give us an error even if we give it too large of an index for the string. It will just return the widest matching slice it can.

Q 2 - What is output for following code −

y = [4, 5,1j]
y.sort()

A - [1j,4,5]

B - [5,4,1j]

C - [4,5,1j]

D - Type Error

Answer : D

Explanation

we cannot compare complex numbers with numbers, so the output results in type error stating that complex numbers cannot be compared with <,>,=.

Q 3 - Syntax error in python is detected by _________at _______

A - compiler/ compile time

B - interpreter/ run time

C - compiler/ run time

D - interpreter/ compile time

Answer : B

Explanation

Syntax error in python is detected by interpreter at run time.

Q 4 - What is output of following code −

s = ''mnopqr ''
i = ''m ''
while i in s:
   print('i', end= '' '')

A - i i i i i i i i..

B - m m m m m ..

C - m n o p q r

D - no output

Answer : A

Q 5 - What command is used to shuffle a list L'?

A - L.shuffle()

B - random.shufflelist(L)

C - shuffle(L)

D - random.Shuffle(L)

Answer : D

Explanation

To shuffle the list we use random.shuffle(List_name) function.

Q 6 - What is the output of the following code?

def f(x = 100, y = 100): 
   return(x+y, x-y) 
x, y = f(y = 200, x = 100) 
print(x, y) 

A - 300 -100

B - 200 0

C - 200 100

D - 0 300

Answer : A

Explanation

In variable y functions runs and gives the output of x + y and x - y i.e 300 and -100 respectively. Then assignment operator is used to assign the value of x and y.

Q 7 - Which among them will produce {'a', 'b', 'c'}?

A - Tuple(''abc'')

B - List(''abc'')

C - Set(''abac'')

D - None of the above.

Answer : D

Explanation

Set does not allow the repetitive values in it and it separated each value present under a string.

Q 8 - Which code is used to open a file for binary writing?

A - ''w''

B - ''wb''

C - ''r+''

D - ''a''

Answer : B

Explanation

b' format is used to work on the binary format of file.

Q 9 - Using the pack manager, how you can you put the components in a container in the same row?

A - Component.pack(side= ''LEFT'')

B - Component.pack(''Left '')

C - Component.pack(side=LEFT)

D - Component.pack(Left-side)

Answer : C

Explanation

It is the default way to do this.

Q 10 - How you can lift the pen of in turtle?

A - Turtle.lift()

B - Turtle.liftup()

C - Turtle.penup()

D - Turtle.up()

Answer : C

python_questions_answers.htm
Advertisements