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 tinylist * 2 if tinylist = [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 an object to a string in python?

A - int(x [,base])

B - long(x [,base] )

C - float(x)

D - str(x)

Answer : D

Explanation

str(x) − Converts object x to a string representation.

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 alphanumeric?

A - shuffle(lst)

B - capitalize()

C - isalnum()

D - isdigit()

Answer : C

Explanation

isalnum() − Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise.

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 len([1, 2, 3])?

A - 1

B - 2

C - 3

D - 4

Answer : C

Explanation

3

Q 10 - What is the following function returns item from the list with max value?

A - cmp(list)

B - len(list)

C - max(list)

D - min(list)

Answer : C

Explanation

max(list) − Returns item from the list with max value.


python_questions_answers.htm

Advertisements
E-Books Store