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 - Is python a case sensitive language?

A - true

B - false

Answer : A

Explanation

Yes! Python is a case sensitive programming language.

Q 2 - What is the output of print str[2:] if str = 'Hello World!'?

A - llo World!

B - H

C - llo

D - None of the above.

Answer : A

Explanation

llo 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 a float in python?

A - int(x [,base])

B - long(x [,base] )

C - float(x)

D - str(x)

Answer : C

Explanation

float(x) − Converts x to a floating-point number.

Q 5 - Which of the following function convert an integer to an unicode character in python?

A - unichr(x)

B - ord(x)

C - hex(x)

D - oct(x)

Answer : A

Explanation

unichr(x) − Converts an integer to a Unicode character.

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 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 removes all leading whitespace in string?

A - lower()

B - lstrip()

C - max(str)

D - min(str)

Answer : B

Explanation

lstrip() − Removes all leading whitespace in string.

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