1
00:00:04,630 --> 00:00:08,170
So let's talk about tuples.

2
00:00:36,410 --> 00:00:37,290
All of the common sequence

3
00:00:37,690 --> 00:00:42,159
operations can be performed on tuples. We
have looked at a table of those

4
00:00:42,159 --> 00:00:50,979
operations, earlier, and let's just bring
that back on the screen again. So these

5
00:00:50,980 --> 00:00:57,140
ones here. Alright, so those there - all
of those can be performed on tuples.

6
00:00:57,140 --> 00:00:59,940
Alright, so let's have a look at some
tuples to see what they look like. I'm

7
00:00:59,949 --> 00:01:04,120
gonna shoot back to IntelliJ, and we're gonna
create a new file here. We're going to

8
00:01:04,120 --> 00:01:09,120
call this one tuples_intro.py.

9
00:01:14,170 --> 00:01:21,220
Alright, so I'm gonna start by typing t equals, in 
double quotes, a comma double quotes,

10
00:01:21,220 --> 00:01:26,920
or in double quotes, b comma, then within
double quotes, c. Then on line 2, I'm going to

11
00:01:26,920 --> 00:01:33,100
print parentheses t. So run the program,

12
00:01:33,100 --> 00:01:36,640
and the output looks very much like a
list. Notice, though, that it prints in

13
00:01:36,640 --> 00:01:40,420
parentheses, instead of square brackets,
and that's how you can tell that you're

14
00:01:40,420 --> 00:01:44,800
dealing with a tuple, rather than a list.
In fact, you can use parentheses when

15
00:01:44,800 --> 00:01:51,820
defining your tuples. I'll enclose our
tuple in parentheses, like so.

16
00:01:51,820 --> 00:01:57,640
Running the program, we get exactly the same
output. The program worked before

17
00:01:57,640 --> 00:02:01,810
without the parentheses, so obviously, they're
optional. Now there are a couple of times,

18
00:02:01,810 --> 00:02:06,580
though, when you must use parentheses. To
keep things simple and avoid having yet

19
00:02:06,580 --> 00:02:11,540
another thing to remember, you may want
to always use parentheses around your tuples.

20
00:02:11,540 --> 00:02:13,320
I'll admit that my style has been not to

21
00:02:13,330 --> 00:02:17,020
use them, unless they're necessary, so
don't be confused if you see an

22
00:02:17,020 --> 00:02:21,680
example that doesn't use them. In fact, I may
slip one or two in without parentheses.

23
00:02:21,680 --> 00:02:25,060
You will find, though, code on-line  that doesn't use parentheses

24
00:02:25,060 --> 00:02:27,489
around tuples, so it certainly won't hurt to be

25
00:02:27,489 --> 00:02:33,500
familiar when reading it. Alright, so
let's see when parentheses are needed.

26
00:02:33,500 --> 00:02:36,720
So we've already seen that we can pass
several arguments to the print function.

27
00:02:36,730 --> 00:02:41,350
Let's open up moreprint.py again. So
I'm going to delete the last line - that's

28
00:02:41,350 --> 00:02:45,220
because we're not interested in
separators for this example.

29
00:02:45,220 --> 00:02:49,540
So on line four, we're telling print to print four items.

30
00:02:49,540 --> 00:02:53,820
We've got the two variable names - name
and age - followed by the string Python

31
00:02:53,820 --> 00:03:01,900
and the int literal 2020. So I run the
program - we get the four values printed out.

32
00:03:01,900 --> 00:03:06,120
The print function interprets that
as four separate variables. Remember that

33
00:03:06,130 --> 00:03:10,390
print allows us to provide multiple
arguments to be printed. What if we

34
00:03:10,390 --> 00:03:14,350
wanted that to be a tuple, instead of
four separate values. In that case,

35
00:03:14,350 --> 00:03:20,180
we have to use parentheses. So I'm gonna come up
here. So l'm gonna duplicate line 4 there,

36
00:03:20,180 --> 00:03:25,260
and on line 5, now, I'm going to add
parentheses around our four objects,

37
00:03:25,260 --> 00:03:31,120
like so, and now if we run it,
we can see the difference there. Line 5

38
00:03:31,120 --> 00:03:35,020
results in a single value - a tuple - being printed.

39
00:03:35,020 --> 00:03:42,620
So parentheses must be used, when you
pass a tuple literal as an argument to a function.

40
00:04:38,199 --> 00:04:39,919
Well in the next few videos, we'll look

41
00:04:39,920 --> 00:04:43,820
at why they are useful, and also see some
more things you can do with them.

42
00:04:43,820 --> 00:04:46,860
See you in the next video

