ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'abcabc'
print(s.index('c'), s.rindex('a'), s.find('bca', 1), s.count('bc', 1, 4))- A. 2 3 1 2
- B. 2 0 1 1
- C. 5 3 4 1
- D. 2 3 1 1
Correct answer: D. 2 3 1 1
index('c') finds the first c at 2, and rindex('a') finds the last a at 3. 'bca' starts at index 1, and the count of 'bc' in s[1:4] = 'bca' is 1.
More Python Programming questions
- What is printed? python nums = [4, 9, 16] print(list(map(pow, nums, [0.5] 3)), [n 0.5 for n in nums])
- What is printed? python def gen(n): for i in range(n): yield i i g = gen(4) print(sum(g), sum(g), list(gen(0)))
- What is printed? python words = ['apple', 'Bob', 'cat'] print(sorted(words, key=str.casefold)[0], sorted(words)[0], max(words, key=len))
- What is printed? python import heapq h = [(2, 'x'), (1, 'y'), (1, 'a')] heapq.heapify(h) heapq.heappush(h, (0, 'z'))…
- What is printed? python s = 'hello world' print(s.title(), s.swapcase()[:5], s.replace('l', '', 2))
- What is printed? python a = [[0] 2 for in range(2)] b = [[0] 2] 2 a[0][1] = 5 b[0][1] = 5 print(a, b)