Course of Raku / Essentials / Typed variables

Type conversion for typed variables

Type constraints are strict enough. For instance, you cannot assign a Num value, even if it contains a whole integer, to a variable declared as Int:

my Int $x = 42;
# $x = 42e1; # Error

Use one of the methods to cast the value.

my Int $x = 42;
$x = 42e1.Int;
$x = Int(42e1);

Practice

Complete the quiz that covers the contents of this topic.

Course navigation

Typed variables / Using of   |   Typed variables / Allomorphs


💪 Or jump directly to the exercises to this section.

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська