This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Strings – 9”.
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
Explanation: .2 specifies the precision.
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
Explanation: The symbol % is used to represent the result of an expression as a percentage.
3. What will be the output of the following Python code?
print('ab12'.isalnum())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The string has only letters and digits.
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
Explanation: The character , is not a letter or a digit.
5. What will be the output of the following Python code?
print('ab'.isalpha())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The string has only letters.
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
Explanation: Space is not a letter.
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
Explanation: Hexadecimal digits aren’t considered as digits (a-f).
8. What will be the output of the following Python code snippet?
print(''.isdigit())
a) True
b) False
c) None
d) Error
View Answer
Explanation: If there are no characters then False is returned.
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
Explanation: It is a valid identifier.
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
Explanation: It is a valid identifier.
Sanfoundry Global Education & Learning Series – Python.
To practice all mcqs on Python, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Apply for Python Internship
- Practice Programming MCQs
- Apply for Programming Internship
- Check Python Books
- Check Information Technology Books