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

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

B - abcd

C - [786, 2.23]

D - None of the above.

Answer : C

Explanation

It will print elements starting from 2nd till 3rd. Output would be [786, 2.23].

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 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 function convert an integer to a character in python?

A - set(x)

B - dict(d)

C - frozenset(s)

D - chr(x)

Answer : D

Explanation

chr(x) − Converts s to a frozen set.

Q 6 - Which of the following function sets the integer starting value used in generating random numbers?

A - choice(seq)

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

C - random()

D - seed([x])

Answer : D

Explanation

seed([x]) − Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. 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 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[-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