ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
x = (5) y = (5,) print(type(x).__name__, type(y).__name__, len(y), ((5),) == (5,))
- A. tuple tuple 1 True
- B. int tuple 2 False
- C. int tuple 1 True
- D. int int 1 True
Correct answer: C. int tuple 1 True
Parentheses alone do not make a tuple; the comma does. (5) is the int 5, while (5,) is a one-item tuple, and ((5),) equals (5,).
More Python Programming questions
- What is printed? python a = {1, 2, 3} b = {3, 4} print(a ^ b, a.issubset({1, 2, 3, 4}), sorted(a - b, reverse=True), b > {3})
- What is printed? python import math print(math.floor(-2.5), math.trunc(-2.5), -7.5 // 2, divmod(7.5, 2))
- What is printed? python def dfs(g, s): seen, out, st = set(), [], [s] while st: u = st.pop() if u in seen: continue seen.add(u)…
- What is printed? python def hanoi(n, a, b, c, out): if n == 0: return hanoi(n - 1, a, c, b, out) out.append((a, c)) hanoi(n - 1, b, a, c…
- What is printed? python from collections import deque def islands(g): R, C = len(g), len(g[0]) seen = set() cnt = 0 for r in range(R): for…
- What is printed? python import heapq def refuel(target, start, stations): h = [] i = 0 fuel = start stops = 0 while fuel < target: while i…