Course of Raku / Essentials / More about types
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; # 300This 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
Practice
Complete the quizzes that cover the contents of this section.
Exercises
This section contains 4 exercises. Examine all the topics of this section before doing the coding practice.
Course navigation
← Quiz: What is its type? | Type constraints →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська