260). What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy'))
[A]2
[B]0
[C]error
[D]none of the mentioned
Show Answer
Correct Answer: 2
Notes:
Answer: a
Explanation: Counts the number of times the substring ‘yy’ is present in the given string.
261). What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 1))
[A]2
[B]0
[C]1
[D]none of the mentioned
Show Answer
Correct Answer: 2
Notes:
Answer: a
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 1.
262). What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 2))
[A]2
[B]0
[C]1
[D]none of the mentioned
Show Answer
Correct Answer: 1
Notes:
Answer: c
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from position 2.
263). What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', 0, 100))
Show Answer
Correct Answer: 2
Notes:
Answer: a
Explanation: An error will not occur if the end value is greater than the length of the string itself.
264). What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', 2, 11))
Show Answer
Correct Answer: 0
Notes:
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.
265). What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('xyy', -10, -1))
Show Answer
Correct Answer: 0
Notes:
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.
266). What will be the output of the following Python code?
print('abc'.encode())
[A]abc
[B]‘abc’
[C]b’abc’
[D]h’abc’
Show Answer
Correct Answer: b’abc’
Notes:
Answer: c
Explanation: A bytes object is returned by encode.
267). What is the default value of encoding in encode()?
print('abc'.encode())
[A]ascii
[B]qwerty
[C]utf-8
[D]utf-16
Show Answer
Correct Answer: utf-8
Notes:
Answer: c
Explanation: The default value of encoding is utf-8.
268). What will be the output of the following Python code?
print("xyyzxyzxzxyy".endswith("xyy"))
Show Answer
Correct Answer: True
Notes:
Answer: b
Explanation: The function returns True if the given string ends with the specified substring.
269). What will be the output of the following Python code?
print("xyyzxyzxzxyy".endswith("xyy", 0, 2))
[A]0
[B]1
[C]True
[D]False
Show Answer
Correct Answer: False
Notes:
Answer: d
Explanation: The function returns False if the given string does not end with the specified substring.