Python Questions and Answers – Strings – 6
This set of Python Quiz focuses on “Strings”.
1. What is the output of the following?
a) 2
b) 0
c) error
d) none of the mentioned
View Answer
b) 0
c) error
d) none of the mentioned
View Answer
Answer: a
Explanation: Counts the number of times the substring ‘yy’ is present in the given string.
Explanation: Counts the number of times the substring ‘yy’ is present in the given string.
2. What is the output of the following?
a) 2
b) 0
c) 1
d) none of the mentioned
View Answer
b) 0
c) 1
d) none of the mentioned
View Answer
Answer: a
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 1.
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 1.
3. What is the output of the following?
a) 2
b) 0
c) 1
d) none of the mentioned
View Answer
b) 0
c) 1
d) none of the mentioned
View Answer
Answer: c
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 2.
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 2.
advertisements
a) 2
b) 0
c) 1
d) error
View Answer
b) 0
c) 1
d) error
View Answer
Answer: a
Explanation: An error will not occur if the end value is greater than the length of the string itself.
Explanation: An error will not occur if the end value is greater than the length of the string itself.
5. What is the output of the following?
a) 2
b) 0
c) 1
d) error
View Answer
b) 0
c) 1
d) error
View Answer
Answer: b
Explanation: Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.
Explanation: Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.
6. What is the output of the following?
a) 2
b) 0
c) 1
d) error
View Answer
b) 0
c) 1
d) error
View Answer
Answer: b
Explanation: Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.
Explanation: Counts the number of times the substring ‘xyy’ is present in the given string, starting from position 2 and ending at position 11.
7. What is the output of the following?
advertisements
b) ‘abc’
c) b’abc’
d) h’abc’
View Answer
Answer: c
Explanation: A bytes object is returned by encode.
Explanation: A bytes object is returned by encode.
8. What is the default value of encoding in encode()?
a) ascii
b) qwerty
c) utf-8
d) utf-16
View Answer
a) ascii
b) qwerty
c) utf-8
d) utf-16
View Answer
Answer: c
Explanation: The default value of encoding is utf-8.
Explanation: The default value of encoding is utf-8.
9. What is the output of the following?
a) 1
b) True
c) 3
d) 2
View Answer
b) True
c) 3
d) 2
View Answer
Answer: b
Explanation: The function returns True if the given string ends with the specified substring.
Explanation: The function returns True if the given string ends with the specified substring.
10. What is the output of the following?
a) 0
b) 1
c) True
d) False
View Answer
b) 1
c) True
d) False
View Answer
Answer: d
Explanation: The function returns False if the given string does not end with the specified substring.
Explanation: The function returns False if the given string does not end with the specified substring.