Engineering Questions with Answers - Multiple Choice Questions

Python MCQs

1 - Question

1. What will be the output of the following Python code?

print('{0:.2}'.format(1/3))

a) 0.333333
b) 0.33
c) 0.333333:.2
d) Error

View Answer

Answer: b
Explanation: .2 specifies the precision.




2 - Question

2. What will be the output of the following Python code?

print('{0:.2%}'.format(1/3))

a) 0.33
b) 0.33%
c) 33.33%
d) 33%

View Answer

Answer: c
Explanation: The symbol % is used to represent the result of an expression as a percentage.




3 - Question

3. What will be the output of the following Python code?

print('ab12'.isalnum())

a) True
b) False
c) None
d) Error

View Answer

Answer: a
Explanation: The string has only letters and digits.




4 - Question

4. What will be the output of the following Python code?

print('ab,12'.isalnum())

a) True
b) False
c) None
d) Error

View Answer

Answer: b
Explanation: The character , is not a letter or a digit.




5 - Question

5. What will be the output of the following Python code?

print('ab'.isalpha())

a) True
b) False
c) None
d) Error

View Answer

Answer: a
Explanation: The string has only letters.




6 - Question

6. What will be the output of the following Python code?

print('a B'.isalpha())

a) True
b) False
c) None
d) Error

View Answer

Answer: b
Explanation: Space is not a letter.




7 - Question

7. What will be the output of the following Python code snippet?

print('0xa'.isdigit())

a) True
b) False
c) None
d) Error

View Answer

Answer: b
Explanation: Hexadecimal digits aren’t considered as digits (a-f).




8 - Question

8. What will be the output of the following Python code snippet?

print(''.isdigit())

a) True
b) False
c) None
d) Error

View Answer

Answer: b
Explanation: If there are no characters then False is returned.




9 - Question

9.What will be the output of the following Python code snippet?

print('my_string'.isidentifier())

a) True
b) False
c) None
d) Error

View Answer

Answer: a
Explanation: It is a valid identifier.




10 - Question

10. What will be the output of the following Python code snippet?

print('__foo__'.isidentifier())

a) True
b) False
c) None
d) Error

View Answer

Answer: a
Explanation: It is a valid identifier.

Get weekly updates about new MCQs and other posts by joining 18000+ community of active learners