ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE
What does the following Python 3 code print? s = "committee" print(s.count("m"), s.find("m"), s.rfind("m"), s.index("m", s.find("m") + 1) if s.count("m") > 1 else -1)
- A. 2 2 3 3
- B. 2 3 2 -1
- C. 2 2 3 2
- D. 7 2 3 -1
Correct answer: A. 2 2 3 3
count tallies non-overlapping matches, find/rfind give first/last index, and index(sub, start) searches from start. Output: 2 2 3 3.
More Python Programming questions
- What does the following Python 3 code print? a, b = [3,7,3,8], [4,1,7,7] print(list(map(lambda p: p[0] p[1], zip(a, b))), len(list(zip(a…
- What does the following Python 3 code print? a, b = set([11,9,12,1,11]), set([3,11,11,5,7,4]) print(sorted(a ^ b), len(a - b))
- What does the following Python 3 code print? def mk(): c = 0 def inc(): nonlocal c c += 4 return c return inc a, b = mk(), mk() for in…
- What does the following Python 3 code print? a, b, c = 30, 3, 39 print((a << b) ^ c, a & ~c, (a | c) >> b)
- What does the following Python 3 code print? def f(): try: return 3 finally: print("f", end=" ") x = f() + 10 print(x)
- What does the following Python 3 code print? a, b = [1,6,5,3], [8,3,5,8] print(list(map(lambda p: p[0] p[1], zip(a, b))), len(list(zip(a…