ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def f(x):
    if x > 0:
        return x
print(f(1), f(-1), f(0) or "zero", f(2) and f(-2))
  1. A. 1 None None None
  2. B. 1 -1 zero -2
  3. C. 1 None zero 2
  4. D. 1 None zero None

Correct answer: D. 1 None zero None

A function that ends without return gives None. `None or 'zero'` returns 'zero'; `2 and None` returns its second operand None, since 2 is truthy.

More Python Programming questions

Exams that ask this topic