This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Strings – 10”.
1. What will be the output of the following Python code snippet?
print('for'.isidentifier())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .isidentifier() method checks whether a string is a valid identifier according to Python’s syntax rules — it doesn’t check whether the string is a keyword. ‘for’ follows the syntax rules for identifiers, so .isidentifier() returns True, even though ‘for’ is a Python keyword and can’t actually be used as a variable name.
2. What will be the output of the following Python code snippet?
print('abc'.islower())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .islower() method returns True if all alphabetic characters in the string are lowercase and there is at least one alphabetic character. Since ‘abc’ contains only lowercase letters, the result is True.
3. What will be the output of the following Python code snippet?
print('a@ 1,'.islower())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .islower() method returns True if all alphabetic characters in the string are lowercase, ignoring non-alphabetic characters like @, space, 1, and ,. Since there are no uppercase letters and the alphabetic characters are lowercase, the result is True.
4. What will be the output of the following Python code snippet?
print('11'.isnumeric())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .isnumeric() method returns True if all characters in the string are numeric characters. Since ’11’ contains only numeric digits, the method returns True.
5. What will be the output of the following Python code snippet?
print('1.1'.isnumeric())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .isnumeric() method returns True only if all characters in the string are numeric characters. Since the string ‘1.1’ contains a dot . which is not numeric, the method returns False.
6. What will be the output of the following Python code snippet?
print('1@ a'.isprintable())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .isprintable() method returns True if all characters in the string are printable, including letters, digits, punctuation, and whitespace. Since ‘1@ a’ contains only printable characters, the result is True.
7. What will be the output of the following Python code snippet?
print(''''''.isspace())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The string ””’ is an empty string (no characters). The .isspace() method returns True only if all characters in the string are whitespace characters. Since the string is empty and contains no characters at all, .isspace() returns False.
8. What will be the output of the following Python code snippet?
print('\t'.isspace())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .isspace() method returns True if all characters in the string are whitespace characters, which include spaces, tabs (\t), newlines, and similar. Since ‘\t’ is a tab character, it counts as whitespace, so the result is True.
9. What will be the output of the following Python code snippet?
print('HelloWorld'.istitle())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .istitle() method checks if each word in the string starts with an uppercase letter followed by lowercase letters. In ‘HelloWorld’, Python treats it as a single word with multiple uppercase letters, which violates the title case rule. Therefore, the output is False.
10. What will be the output of the following Python code snippet?
print('Hello World'.istitle())
a) True
b) False
c) None
d) Error
View Answer
Explanation: The .istitle() method returns True if each word in the string starts with an uppercase letter followed by lowercase letters. In ‘Hello World’, both “Hello” and “World” follow this rule, so the method returns True.
Sanfoundry Global Education & Learning Series – Python.
To practice all test questions on Python, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Practice Programming MCQs
- Check Information Technology Books
- Check Python Books
- Apply for Programming Internship
- Apply for Python Internship