Skip to content

Commit aa58e74

Browse files
committed
Add tuple section for Python to Raku page.
This is to help users coming from any language with Tuples find a page listing an equivalent Raku feature.
1 parent 711924f commit aa58e74

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

doc/Language/py-nutshell.pod6

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,32 @@ in the C<user_input> variable. This is similar to L<prompt|/routine/prompt> in R
761761
my $user_input = prompt("Say hi → ");
762762
say $user_input; # OUTPUT: whatever you entered.
763763
764+
=head2 X<Tuples|Python>
765+
766+
Python tuples are immutable sequences. The sequence elements do not need
767+
to be of the same types.
768+
769+
Python
770+
771+
=for code :lang<python>
772+
tuple1 = (1, "two", 3, "hat")
773+
tuple2 = (5, 6, "seven")
774+
print(tuple1[1]) # OUTPUT: «two␤»
775+
tuple3 = tuple1 + tuple2
776+
print(tuple3) # OUTPUT: «(1, 'two', 3, 'hat', 5, 6, 'seven')␤»
777+
778+
Raku
779+
780+
Raku does not have a builtin Tuple type, though they are available as modules.
781+
You can obtain the same behavior from Raku using the List type.
782+
783+
my $list1 = (1, "two", 3, "hat");
784+
my $list2 = (5, 6, "seven");
785+
say $list1[1]; # OUTPUT: «two␤»
786+
my $list3 = slip($list1), slip($list2);
787+
my $list4 = |$list1, |$list2; # equivalent to previous line
788+
say $list3; # OUTPUT: «(1, two, 3, hat, 5, 6, seven)␤»
789+
764790
=end pod
765791

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

0 commit comments

Comments
 (0)