Python Online Quiz


Advertisements


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 - Which of the following environment variable for Python is an alternative module search path?

A - PYTHONPATH

B - PYTHONSTARTUP

C - PYTHONCASEOK

D - PYTHONHOME

Answer : D

Explanation

PYTHONHOME − It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.

Q 2 - What is the output of print str[0] if str = 'Hello World!'?

A - Hello World!

B - H

C - ello World!

D - None of the above.

Answer : B

Explanation

H is the correct answer.

Q 4 - Which of the following function convert a String to a set in python?

A - set(x)

B - dict(d)

C - frozenset(s)

D - chr(x)

Answer : A

Explanation

set(s) − Converts s to a set.

Q 5 - Which of the following operator in python performs the division on operands where the result is the quotient in which the digits after the decimal point are removed?

A - **

B - //

C - is

D - not in

Answer : B

Explanation

// Floor Division − The division of operands where the result is the quotient in which the digits after the decimal point are removed.

Q 6 - Which of the following function returns a random item from a list, tuple, or string?

A - choice(seq)

B - randrange ([start,] stop [,step])

C - random()

D - seed([x])

Answer : A

Explanation

choice(seq) − Returns a random item from a list, tuple, or string.

Q 7 - Which of the following function gets a space-padded string with the original string left-justified to a total of width columns?

A - isupper()

B - join(seq)

C - len(string)

D - ljust(width[, fillchar])

Answer : D

Explanation

ljust(width[, fillchar]) − Returns a space-padded string with the original string left-justified to a total of width columns.

Q 8 - Which of the following function removes all leading and trailing whitespace in string?

A - replace(old, new [, max])

B - strip([chars])

C - swapcase()

D - title()

Answer : B

Explanation

strip([chars]) − Performs both lstrip() and rstrip() on string.

Q 9 - What is the output of L[2] if L = [1,2,3]?

A - 1

B - 2

C - 3

D - None of the above.

Answer : C

Explanation

3, Offsets start at zero.

Q 10 - What is the following function reverses objects of list in place?

A - list.reverse()

B - list.sort([func])

C - list.pop(obj=list[-1])

D - list.remove(obj)

Answer : A

Explanation

list.reverse() − Reverses objects of list in place.


python_questions_answers.htm

Advertisements