Python Online Quiz



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 - What is output for −

a = ['hat', 'mat', 'rat']

'rhyme'.join(a)

A - [hat','mat','rat','rhyme']

B - hatmatratrhyme'

C - [hat mat rat rhyme']

D - hatrhymematrhyme rat'

Answer : D

Explanation

The method join() takes list of string as input and returns string as output. It removes ,' and add the given string with join to the list.

Q 2 - What is output of following code −

x = 2
y = 10
x * = y * x + 1

A - 42

B - 41

C - 40

D - 39

Answer : A

Explanation

x * = y * x + 1 means x = x * (y * x + 1)

Q 3 - What is output of following code −

print('hijk'.partition('ab'))

A - ('hijk', 'cd', ' ')

B - ('hijk')

C - ('hijk', ' ', ' ')

D - Name error

Answer : C

Explanation

Since there are no separators in the given string so the output is the same string.

Q 4 - What is output for − min(''hello world'')

A - e

B - a blank space character

C - w

D - None of the above.

Answer : B

Explanation

python considers a blank space character as minimum value in a string.

Q 5 - What will be the output of the following code?

def total(initial = 5, *num, **key):
   count = initial
   for n in num:
      count+=n
   for k in key:
      count+=key[k]
   return count
print(total(100,2,3, clouds=50, stars=100))

A - 260

B - 160

C - 155

D - 255

Answer : D

Explanation

It takes initial value as 100 now. And adds 2, 3, 50 and 100 to it as according to code.

Q 6 - What is the output of the following code?

def f(x = 100, y = 100): 
   return(x+y, x-y) 
x, y = f(y = 200, x = 100) 
print(x, y) 

A - 300 -100

B - 200 0

C - 200 100

D - 0 300

Answer : A

Explanation

In variable y functions runs and gives the output of x + y and x - y i.e 300 and -100 respectively. Then assignment operator is used to assign the value of x and y.

Q 7 - Which of the function among will return 4 on the set s = {3, 4, 1, 2}?

A - Sum(s)

B - Len(s)

C - Max(s)

D - Four(s)

Answer : B & C.

Explanation

len(s) returns the length of the set and max(s) returns the maximum value in the set.

Answer : D

Explanation

You need to define the format in which you want to open the file. Proper path has to be declared by the user for the interpreter to reach the destination of the file.

Answer : B

Explanation

Text is created in the canvas by using create_text method of canvas. Color of the text can be set according to the user which is specified under filled'.

Q 10 - Which can be an Identifier among them in Python?

A - 1abc

B - $12a

C - _xy1

D - @python

Answer : C

Explanation

Because Identifiers start from letter A to Z or a to z or an underscore (_) followed by more letters or zero or underscores and digits (0 to 9). Python does not allow @ or $ or % within the identifier.

python_questions_answers.htm
Advertisements