Data types · 28 / 29 Exercise Medium

Truthy or falsy

Objective

In Python every value has a truth value: None, False, zero, empty strings and empty collections are falsy; everything else is truthy. It is used in if without writing comparisons.

Instructions

  • Read an integer n and then n lines, each with a Python literal (for example 0, [] or "hello").
  • Evaluate each literal with ast.literal_eval and show literal: truthy if it is truthy or literal: falsy if it is falsy.
Input
3
0
[1]
""
Output
0: falsy
[1]: truthy
"": falsy

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise