Python Mock Test


Advertisements

This section presents you various set of Mock Tests related to Python. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Python Mock Test IV

Q 1 - Which of the following function removes all leading and trailing whitespace in string?

A - replace(old, new [, max])

B - strip([chars])

C - swapcase()

D - title()

Answer : B

Explanation

strip([chars]) − Performs both lstrip() and rstrip() on string.

Q 2 - Which of the following function changes case for all letters in string?

A - replace(old, new [, max])

B - strip([chars])

C - swapcase()

D - title()

Answer : C

Explanation

swapcase() − Inverts case for all letters in string.

Q 3 - Which of the following function returns titlecased version of string?

A - replace(old, new [, max])

B - strip([chars])

C - swapcase()

D - title()

Answer : D

Explanation

title() − Returns "titlecased" version of string, that is, all words begin with uppercase and the rest are lowercase.

Q 4 - 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.

Q 5 - 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 6 - What is the output of len([1, 2, 3])?

A - 1

B - 2

C - 3

D - 4

Answer : C

Explanation

3

Q 7 - What is the output of [1, 2, 3] + [4, 5, 6]?

A - [1, 2, 3, 4, 5, 6]

B - [1, 2, 3],[4, 5, 6]

C - [5, 7,9]

D - 21

Answer : A

Explanation

[1, 2, 3, 4, 5, 6]

Answer : A

Explanation

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

Q 9 - What is the output of 3 in [1, 2, 3]?

A - true

B - false

C - Error

D - None of the above.

Answer : A

Explanation

true

Q 10 - What is the output of for x in [1, 2, 3]: print x?

A - x x x

B - 1 2 3

C - Error

D - None of the above.

Answer : B

Explanation

1 2 3

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

A - 1

B - 2

C - 3

D - None of the above.

Answer : C

Explanation

3, Offsets start at zero.

Q 12 - 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 13 - 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 14 - What is the following function compares elements of both lists?

A - cmp(list1, list2)

B - len(list1, list2)

C - max(list1, list2)

D - min(list1, list2)

Answer : A

Explanation

cmp(list1, list2) − Compares elements of both lists.

Q 15 - What is the following function gives the total length of the list?

A - cmp(list)

B - len(list)

C - max(list)

D - min(list)

Answer : B

Explanation

len(list) − Gives the total length of the list.

Q 16 - What is the following function returns item from the list with max value?

A - cmp(list)

B - len(list)

C - max(list)

D - min(list)

Answer : C

Explanation

max(list) − Returns item from the list with max value.

Q 17 - What is the following function returns item from the list with min value?

A - cmp(list)

B - len(list)

C - max(list)

D - min(list)

Answer : D

Explanation

min(list) − Returns item from the list with min value.

Q 18 - What is the following function returns the lowest index in list that obj appears?

A - list.index(obj)

B - list.insert(index, obj)

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

D - list.remove(obj)

Answer : A

Explanation

list.index(obj) − Returns the lowest index in list that obj appears.

Q 19 - What is the following function inserts an object at given index in a list?

A - list.index(obj)

B - list.insert(index, obj)

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

D - list.remove(obj)

Answer : B

Explanation

list.insert(index, obj) − Inserts object obj into list at offset index.

Q 20 - What is the following function removes last object from a list?

A - list.index(obj)

B - list.insert(index, obj)

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

D - list.remove(obj)

Answer : C

Explanation

list.pop(obj=list[-1]) − Removes and returns last object or obj from list.

Q 21 - What is the following function removes an object from a list?

A - list.index(obj)

B - list.insert(index, obj)

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

D - list.remove(obj)

Answer : D

Explanation

list.remove(obj) − Removes object obj from list.

Q 22 - What is the following function reverses objects of list in place?

A - list.reverse()

B - list.sort([func])

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

D - list.remove(obj)

Answer : A

Explanation

list.reverse() − Reverses objects of list in place.

Q 23 - 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.

Q 24 - 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.

Q 25 - 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.

Answer Sheet

Question Number Answer Key
1 B
2 C
3 D
4 A
5 B
6 C
7 A
8 A
9 A
10 B
11 C
12 A
13 A
14 A
15 B
16 C
17 D
18 A
19 B
20 C
21 D
22 A
23 B
24 C
25 C
python_questions_answers.htm
Advertisements