← Back to challenges

Truthy or Falsy?

PythonMediumconditionscontrol_flowvalidationlanguage_fundamentals

Instructions

A "truthy" value is a value that translates to True when evaluated in a Boolean context. All values are truthy unless they're defined as falsy.

All falsy values are as follows:

  • False
  • None
  • 0
  • []
  • {}
  • ""

Create a function that takes an argument of any data type and returns 1 if it's truthy and 0 if it's falsy.

Examples

is_truthy(0) ➞ 0

is_truthy(False) ➞ 0

is_truthy("") ➞ 0

is_truthy("False") ➞ 1
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find the Unique Letters