ProgrammingModerateAccenture · Capgemini pattern
What is printed?
What is printed?
print(int(" -0012 "), int("1_000"), float("1e3"), int("101", 2), int(-2.9))- A. -12 1000 1000 5 -3
- B. -12 1000 1000.0 5 -2
- C. ValueError
- D. -12 1000 1000.0 101 -2
Correct answer: B. -12 1000 1000.0 5 -2
int() ignores surrounding whitespace and leading zeros, accepts a sign and (since 3.6) underscores between digits. float("1e3") is 1000.0. int(s, 2) parses binary: 101 is 5. int() on a float truncates toward zero, so -2.9 becomes -2, not -3.
More Python Programming questions
- What is printed? python def g(): try: yield 1 yield 2 finally: print("cleanup", end=" ") it = g() print(next(it), end=" ") it.close()…
- What is printed? python data = [4, 7, 1, 9] best = 0 hi = [best := x for x in data if x > best] print(hi, best, "x" in globals())
- What is printed? python class M: def init(self, v): self.v = v def add(self, o): return M(self.v + (o.v if isinstance(o, M) else o)) ms =…
- What is printed? python print(f"{3.14159:.2f}|{42:>5}|{'ab':^6}|{255:#x}|{1234567:,}")
- What is printed? python grid = [[0, 0]] 2 copy1 = list(grid) copy2 = [row[:] for row in grid] grid[0][0] = 1 grid[1] = [5, 5] print(copy1…
- What is printed? python vals = iter([3, 1, 0, 4, 0]) print(list(iter(lambda: next(vals), 0)), list(vals))