Typed variables
In Raku, a scalar variable (or, a scalar container) can keep a single object of different types. For example, the same variable can first contain a number, and then a string:
my $var = 42;
$var = 'Hello';
Here is another example of mixing different data types in the same expression:
my $a = '100';
my $b = 200;
say $a + $b; # 300
This is, probably, not the best coding practice, but it is a perfectly valid Raku program.
Nevertheless, Raku allows you to specify what a given variable may keep. There are more details in the below topics.
Topics in this section
Exercises
This section contains 4 exercises. Examine all the topics of this section before going to the coding practice.
Course navigation
← Data type conversion / Converting types with prefix operators | Type constraints →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська