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 list if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

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

B - list

C - Error

D - None of the above.

Answer : A

Explanation

[ 'abcd', 786 , 2.23, 'john', 70.2 ] is the correct answer.

Q 3 - 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 a String to an object in python?

A - repr(x)

B - eval(str)

C - tuple(s)

D - list(s)

Answer : B

Explanation

eval(str) − Evaluates a string and returns an object.

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 operator in python evaluates to true if it does not finds a variable in the specified sequence and false otherwise?

A - **

B - //

C - is

D - not in

Answer : D

Explanation

not in − Evaluates to true if it does not finds a variable in the specified sequence and false otherwise. x not in y, here not in results in a 1 if x is not a member of sequence y.

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

A - islower()

B - isnumeric()

C - isspace()

D - istitle()

Answer : D

Explanation

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

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

A - upper()

B - isdecimal()

C - swapcase()

D - title()

Answer : B

Explanation

isdecimal() − Returns true if a unicode string contains only decimal characters and false otherwise.

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

A - 2,3

B - 2

C - 3

D - None of the above.

Answer : A

Explanation

2, 3, Slicing fetches sections.

Q 10 - What is the following function sorts a list?

A - list.reverse()

B - list.sort([func])

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

D - list.remove(obj)

Answer : B

Explanation

list.sort([func]) − Sorts objects of list, use compare func if given.


python_questions_answers.htm

Advertisements