Python Mock Test



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 III

Q 1 - 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 2 - Which of the following statement terminates the loop statement and transfers execution to the statement immediately following the loop?

A - break

B - continue

C - pass

D - None of the above.

Answer : A

Explanation

break statement − Terminates the loop statement and transfers execution to the statement immediately following the loop.

Q 3 - Which of the following statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating?

A - break

B - continue

C - pass

D - None of the above.

Answer : B

Explanation

continue statement − Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

Q 4 - Which of the following statement is used when a statement is required syntactically but you do not want any command or code to execute?

A - break

B - continue

C - pass

D - None of the above.

Answer : C

Explanation

pass statement − The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute.

Q 5 - Which of the following function returns a random item from a list, tuple, or string?

A - choice(seq)

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

C - random()

D - seed([x])

Answer : A

Explanation

choice(seq) − Returns a random item from a list, tuple, or string.

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 returns a random float r, such that 0 is less than or equal to r and r is less than 1?

A - choice(seq)

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

C - random()

D - seed([x])

Answer : C

Explanation

random() − returns a random float r, such that 0 is less than or equal to r and r is less than 1.

Q 8 - 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 9 - Which of the following function randomizes the items of a list in place?

A - shuffle(lst)

B - capitalize()

C - isalnum()

D - isdigit()

Answer : A

Explanation

shuffle(lst) − Randomizes the items of a list in place. Returns None.

Q 10 - Which of the following function capitalizes first letter of string?

A - shuffle(lst)

B - capitalize()

C - isalnum()

D - isdigit()

Answer : B

Explanation

capitalize() − Capitalizes first letter of string.

Q 11 - Which of the following function checks in a string that all characters are alphanumeric?

A - shuffle(lst)

B - capitalize()

C - isalnum()

D - isdigit()

Answer : C

Explanation

isalnum() − Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise.

Q 12 - Which of the following function checks in a string that all characters are digits?

A - shuffle(lst)

B - capitalize()

C - isalnum()

D - isdigit()

Answer : D

Explanation

isdigit() − Returns true if string has at least 1 character and all characters are digits and false otherwise.

Q 13 - Which of the following function checks in a string that all characters are in lowercase?

A - islower()

B - isnumeric()

C - isspace()

D - istitle()

Answer : A

Explanation

islower() − Returns true if string has at least 1 character and all characters are in lowercase.

Q 14 - 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 15 - Which of the following function checks in a string that all characters are whitespaces?

A - islower()

B - isnumeric()

C - isspace()

D - istitle()

Answer : C

Explanation

isspace() − Returns true if string has at least 1 character and all characters are whitespaces.

Q 16 - Which of the following function checks in a string that all characters are titlecased?

A - islower()

B - isnumeric()

C - isspace()

D - istitle()

Answer : D

Explanation

istitle() − Returns true if string has at least 1 character and all characters are titlecased.

Q 17 - Which of the following function checks in a string that all characters are in uppercase?

A - isupper()

B - join(seq)

C - len(string)

D - ljust(width[, fillchar])

Answer : A

Explanation

isupper() − Returns true if string has at least 1 character and all characters are in uppercase.

Q 18 - Which of the following function merges elements in a sequence?

A - isupper()

B - join(seq)

C - len(string)

D - ljust(width[, fillchar])

Answer : B

Explanation

join(seq) − Merges (concatenates) the string representations of elements in sequence seq into a string, with separator string.

Q 19 - Which of the following function gets the length of the string?

A - isupper()

B - join(seq)

C - len(string)

D - ljust(width[, fillchar])

Answer : C

Explanation

len(string) − Returns the length of the string.

Q 20 - 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 21 - Which of the following function converts a string to all lowercase?

A - lower()

B - lstrip()

C - max(str)

D - min(str)

Answer : A

Explanation

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

Q 22 - 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 23 - Which of the following function returns the max alphabetical character from the string str?

A - lower()

B - lstrip()

C - max(str)

D - min(str)

Answer : C

Explanation

max(str) − Returns the max alphabetical character from the string str.

Q 24 - Which of the following function returns the min alphabetical character from the string str?

A - lower()

B - lstrip()

C - max(str)

D - min(str)

Answer : D

Explanation

min(str) − Returns the min alphabetical character from the string str.

Q 25 - Which of the following function replaces all occurrences of old substring in string with new string?

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

B - strip([chars])

C - swapcase()

D - title()

Answer : A

Explanation

replace(old, new [, max]) − Replaces all occurrences of old in string with new or at most max occurrences if max given.

Answer Sheet

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