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 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 3 - What is the output of print tuple[1:3] if tuple = ( '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 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 operator in python performs exponential (power) calculation on operands?

A - **

B - //

C - is

D - not in

Answer : A

Explanation

** Exponent − Performs exponential (power) calculation on operands. a**b = 10 to the power 20 if a = 10 and b = 20.

Q 6 - Which of the following function returns a randomly selected element from range?

A - choice(seq)

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

C - random()

D - seed([x])

Answer : B

Explanation

randrange ([start,] stop [,step]) − returns a randomly selected element from range(start, stop, step).

Q 7 - Which of the following function gets a space-padded string with the original string left-justified to a total of width columns?

A - isupper()

B - join(seq)

C - len(string)

D - ljust(width[, fillchar])

Answer : D

Explanation

ljust(width[, fillchar]) − Returns a space-padded string with the original string left-justified to a total of width columns.

Q 8 - Which of the following function converts a string to all uppercase?

A - upper()

B - isdecimal()

C - swapcase()

D - title()

Answer : A

Explanation

upper() − Converts all lowercase letters in string to uppercase.

Answer : A

Explanation

['Hi!', 'Hi!', 'Hi!', 'Hi!']

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

A - dict1.cmp(dict2)

B - dict1.sort(dict2)

C - cmp(dict1, dict2)

D - None of the above.

Answer : C

Explanation

cmp(dict1, dict2) − Compares elements of both dict.


python_questions_answers.htm

Advertisements