Course of Raku / Essentials / Variables and data types essentials / Scalar variables
Assigning a value
Use the = operator to put a new value into a scalar
container.
my $name;
$name = 'Anna';You can now use the variable and, for example, print it:
say $name;Multiple assignments
Multiple variables can be assigned at once. For example, this is how to assign two scalars in a single statement:
my ($a, $b);
($a, $b) = 10, 20;Notice that you cannot omit the parentheses on the left-hand side. But you can add them for symmetry on the right side:
($a, $b) = (10, 20);Practice
Complete the quizzes that cover the contents of this topic.
Course navigation
← Quiz 2: Declaring more variables | Quiz 1: Assigning a value →
💪 Or jump directly to the exercises in this
section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська