ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
x = [10, 20, 30, 40, 50] print(x[-1], x[len(x) // 2], x[-2:])
- A. 50 30 [40, 50]
- B. 50 20 [40, 50]
- C. 10 30 [40]
- D. 50 30 [50, 40]
Correct answer: A. 50 30 [40, 50]
x[-1] is the last element, 50. len(x) // 2 = 5 // 2 = 2, and x[2] is 30. x[-2:] starts two from the end and runs to the end in the original order: [40, 50].
More Python Programming questions
- What is printed? python s = "Python" print(s.find("th"), s.find("z"), s.upper()[1:3])
- 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])