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 contains the path of an initialization file containing Python source code?

A - PYTHONPATH

B - PYTHONSTARTUP

C - PYTHONCASEOK

D - PYTHONHOME

Answer : B

Explanation

PYTHONSTARTUP − It contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commands that load utilities or modify PYTHONPATH.

Q 2 - What is the output of print list[0] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

A - [ 'abcd', 786 , 2.23, 'john', 70.2 ]

B - abcd

C - Error

D - None of the above.

Answer : B

Explanation

It will print first element of the list. Output would be abcd.

Q 3 - What is the output of print tinytuple * 2 if tinytuple = (123, 'john')?

A - (123, 'john', 123, 'john')

B - (123, 'john') * 2

C - Error

D - None of the above.

Answer : A

Explanation

It will print list two times. Output would be (123, 'john', 123, 'john').

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

A - repr(x)

B - eval(str)

C - tuple(s)

D - list(s)

Answer : D

Explanation

list(s) − Converts s to a list.

Q 5 - Which of the following function convert an integer to octal string in python?

A - unichr(x)

B - ord(x)

C - hex(x)

D - oct(x)

Answer : D

Explanation

oct(x) − Converts an integer to an octal string.

Q 6 - Which of the following function randomizes the items of a list in place?

A - shuffle(lst)

B - capitalize()

C - isalnum()

D - isdigit()

Answer : A

Explanation

shuffle(lst) − Randomizes the items of a list in place. Returns None.

Q 7 - Which of the following function checks in a string that all characters are numeric?

A - islower()

B - isnumeric()

C - isspace()

D - istitle()

Answer : B

Explanation

isnumeric() − Returns true if string has at least 1 character and all characters are numeric.

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.

Answer : A

Explanation

['Hi!', 'Hi!', 'Hi!', 'Hi!']

Q 10 - What is the following function removes last object from a list?

A - list.index(obj)

B - list.insert(index, obj)

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

D - list.remove(obj)

Answer : C

Explanation

list.pop(obj=list[-1]) − Removes and returns last object or obj from list.


python_questions_answers.htm

Advertisements
E-Books Store