ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
s = "Mississippi"
print(s.count("ss"), s.count("issi"), s.replace("ss", "S"), s.lower().index("s", 4))- A. 2 1 MiSiSippi 5
- B. 2 2 MiSiSippi 5
- C. 2 1 MiSSippi 5
- D. 2 1 MiSiSippi 6
Correct answer: A. 2 1 MiSiSippi 5
count and replace scan left to right for non-overlapping matches: 'ss' occurs twice, while 'issi' occurs at 1 and again overlapping at 4, so only one is counted. index('s', 4) starts at index 4 ('i') and finds 's' at 5.
More Python Programming questions
- What is printed? python print("a" "b" 2, ("a" + "b") 2, "-".join(["a", "b"]) 2, "x".join("123"))
- What is printed? python s = "abc" print(repr(s[1:1] + s[3:] + s[-1:-2]), s[0:0] == s[5:9], len(s[-5:5]), s[True:])
- What is printed? python w = ["bob", "Al", "al", "Bo"] print(sorted(w), sorted(w, key=str.lower))
- What is printed? python people = [("ann", 30), ("bob", 25), ("cid", 30), ("dan", 25)] people.sort(key=lambda p: p[0], reverse=True)…
- What is printed? python nums = [4, -1, 3, -1, 2] print(sorted(nums, key=lambda v: (v < 0, -v)), sorted(set(nums), reverse=True)[:2])
- What is printed? python def walk(d, depth=0): out = [] for k, v in d.items(): out.append(f"{k}{depth}") if isinstance(v, dict): out +=…