ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
s = "level"
t = "".join(reversed(s))
u = s[::-1]
print(s == t == u, t is s, list(reversed([1, 2])) == [2, 1], reversed("ab") == reversed("ab"))- A. True True True True
- B. True False True True
- C. False False True False
- D. True False True False
Correct answer: D. True False True False
'level' is a palindrome, so all three are equal. join builds a new string object. reversed() returns iterator objects, and two distinct iterators compare by identity, so False.
More Python Programming questions
- What is printed? python marks = [72, 85, 64, 85, 90] print(marks.index(85), marks.count(85), sorted(marks)[len(marks) // 2]…
- What is printed? python inventory = {"pen": 3, "ink": 0} inventory["pad"] = inventory.get("pad", 0) + 5 inventory.update(ink=2)…
- What is printed? python def area(w, h=None): if h is None: h = w return w h print(area(3), area(3, 4), area(h=2, w=5), area([2, 6]))
- What is printed? python q = [1, 2, 3] stack = [1, 2, 3] print(q.pop(0), stack.pop(), q, stack, q + stack)
- What is printed? python s = "2024-01-15" y, m, d = map(int, s.split("-")) print(y + m + d, f"{d:02d}/{m:02d}/{y}", s[5:7] == "01")
- What is printed? python scores = [("a", 50), ("b", 80), ("c", 65)] passed = [n for n, s in scores if s >= 60] top = max(scores, key=lambda…