Skip to content

Commit

Permalink
Merge pull request #3445 from Michael-S/master
Browse files Browse the repository at this point in the history
Add tuple section for Python to Raku page.
  • Loading branch information
JJ committed May 30, 2020
2 parents 711924f + aa58e74 commit 9e8e24d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/Language/py-nutshell.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,32 @@ in the C<user_input> variable. This is similar to L<prompt|/routine/prompt> in R
my $user_input = prompt("Say hi → ");
say $user_input; # OUTPUT: whatever you entered.
=head2 X<Tuples|Python>
Python tuples are immutable sequences. The sequence elements do not need
to be of the same types.
Python
=for code :lang<python>
tuple1 = (1, "two", 3, "hat")
tuple2 = (5, 6, "seven")
print(tuple1[1]) # OUTPUT: «two␤»
tuple3 = tuple1 + tuple2
print(tuple3) # OUTPUT: «(1, 'two', 3, 'hat', 5, 6, 'seven')␤»
Raku
Raku does not have a builtin Tuple type, though they are available as modules.
You can obtain the same behavior from Raku using the List type.
my $list1 = (1, "two", 3, "hat");
my $list2 = (5, 6, "seven");
say $list1[1]; # OUTPUT: «two␤»
my $list3 = slip($list1), slip($list2);
my $list4 = |$list1, |$list2; # equivalent to previous line
say $list3; # OUTPUT: «(1, two, 3, hat, 5, 6, seven)␤»
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 comments on commit 9e8e24d

Please sign in to comment.