Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
Python - Data Types as Values
What will be the output of this code snippet?
def check(value):
    if value:
        return "Truthy"
    else:
        return "Falsy"

print(check([]))
print(check([0]))
ATruthy\nFalsy
BFalsy\nTruthy
CFalsy\nFalsy
DTruthy\nTruthy
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function behavior

    The function returns "Truthy" if the value is truthy, else "Falsy".
  2. Step 2: Evaluate the inputs

    [] is empty list (falsy), [0] is list with one element (truthy).
  3. Final Answer:

    Falsy\nTruthy -> Option B
  4. Quick Check:

    Empty list falsy, non-empty list truthy [OK]
Quick Trick: Empty containers are falsy, non-empty are truthy [OK]
Common Mistakes:
MISTAKES
  • Assuming list with zero is falsy
  • Confusing empty list as truthy
  • Mixing return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes