ProgrammingModerateInfosys · Accenture · Capgemini pattern
What is printed?
What is printed?
print(-2 ** 2, (-2) ** 2, 2 ** -1)
- A. 4 4 0.5
- B. 4 -4 0.5
- C. -4 4 0.5
- D. -4 4 0
Correct answer: C. -4 4 0.5
** binds tighter than unary minus, so -2 ** 2 = -(2 ** 2) = -4. With brackets, (-2) ** 2 = 4. A negative exponent always gives a float: 2 ** -1 = 0.5.
More Python Programming questions
- What is printed? python print(0 or [] or "x", 1 and 0 and 5, None or 0)
- What is printed? python x = [1, 2] g = (n 10 for n in x) x.append(3) x = [7] print(list(g))
- What is printed? python class Bag: items = [] def add(self, v): self.items.append(v) a, b = Bag(), Bag() a.add(1); b.add(2) print(a.items…
- What is printed? python class A: def who(self): return "A" class B(A): def who(self): return "B" + super().who() class C(A): def…
- What is printed? python try: try: raise ValueError except TypeError: print("T", end=" ") finally: print("F1", end=" ") except ValueError…
- What is printed? python x = 10 def f(a=x): return a x = 20 print(f())