Python MCQ – String – 9

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

Answer: b
Explanation: .2 specifies the precision.
advertisement
advertisement

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. What will be the output of the following Python code?

advertisement
print('ab12'.isalnum())

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

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

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

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]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.