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 used in Windows to instruct Python to find the first case-insensitive match in an import statement?

A - PYTHONPATH

B - PYTHONSTARTUP

C - PYTHONCASEOK

D - PYTHONHOME

Answer : C

Explanation

PYTHONCASEOK − It is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable to any value to activate it.

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

A - Hello World!Hello World!

B - Hello World! * 2

C - Hello World!

D - None of the above.

Answer : A

Explanation

Hello World!Hello World! is the correct answer.

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 hexadecimal string in python?

A - unichr(x)

B - ord(x)

C - hex(x)

D - oct(x)

Answer : C

Explanation

hex(x) − Converts an integer to a hexadecimal string.

Q 6 - Which of the following statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating?

A - break

B - continue

C - pass

D - None of the above.

Answer : B

Explanation

continue statement − Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

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

A - islower()

B - isnumeric()

C - isspace()

D - istitle()

Answer : A

Explanation

islower() − Returns true if string has at least 1 character and all characters are in lowercase.

Q 8 - Which of the following function replaces all occurrences of old substring in string with new string?

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

B - strip([chars])

C - swapcase()

D - title()

Answer : A

Explanation

replace(old, new [, max]) − Replaces all occurrences of old in string with new or at most max occurrences if max given.

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 : A

Explanation

1, Negative: count from the right.

Q 10 - What is the following function compares elements of both dictionaries dict1, dict2?

A - max(dict)

B - min(dict)

C - len(dict)

D - None of the above.

Answer : C

Explanation

len(dict) − Gives the total length of the dictionary. This would be equal to the number of items in the dictionary.


python_questions_answers.htm

Advertisements