Course of Raku / Essentials / Data type conversion / Exercises / True and False strings

Solution: True and False strings

This exercise is similar to the previous one, but this time, the task is a bit trickier. There are more ’suspect’ strings that can be treated as False. Let us explore them.

say ?'';

say ?' ';
say ?'        ';

say ?"\n";

say ?'0';
say ?'0.0';

From all of these, only the empty string is cast as False. All other strings, even those that contain only spaces or an explicit character 0, become True.

🦋 You can find the full program with the above example in the file true-false-strings.raku.

Next exercise

💪 Fractional part

Course navigation

Loops / Postfix form of for   |   Typed variables