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);
Course navigation
←
Typed variables / Using of
|
Typed variables / Allomorphs
→
💪 Or jump directly to the exercises to this section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська