ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
s = "Python"
print(s.find("th"), s.find("z"), s.upper()[1:3])- A. 2 None YT
- B. 3 -1 YT
- C. 2 -1 YTH
- D. 2 -1 YT
Correct answer: D. 2 -1 YT
find returns the index where the substring starts ("th" starts at index 2) and -1 when it is absent; it never returns None (index() would raise ValueError). "PYTHON"[1:3] takes indices 1 and 2: "YT".
More Python Programming questions
- What is printed? python s = "a-b-c-d" print(s.split("-", 2), s.rsplit("-", 1))
- What is printed? python print("hello world".title(), "ab".center(6, ""), "42".zfill(5), "-7".zfill(4))
- What is printed? python d = dict(zip("abc", range(3))) d.update({"b": 9, "d": 1}) print(list(d.items())[1], sum(d.values()), len(d))
- What is printed? python a = {1, 2, 3, 4} b = {3, 4, 5} print(a - b, b - a, len(a | b), a & b == {4, 3})
- What is printed? python print(" ".join(i ch for i, ch in enumerate("xyz", 1)), list(enumerate("ab"))[-1])
- What is printed? python nums = list(range(10)) print(nums[8:2:-2], nums[-3:], nums[2:8:-1])