1
00:00:05,250 --> 00:00:09,270
Welcome back, everyone, to this lecture, we're going to be discussing Tuples and Boyens.

2
00:00:10,420 --> 00:00:14,260
Tuples are similar to lists, except for the fact that they are immutable.

3
00:00:14,500 --> 00:00:20,290
That means they can't be changed or mutated, so immutability means you can't go in and swap out an

4
00:00:20,290 --> 00:00:21,940
item that's already in that tuple.

5
00:00:22,300 --> 00:00:28,300
So tuples are still a sequence just like a list, but you can't change them now due to the immutability.

6
00:00:28,570 --> 00:00:32,740
That means they're going to have less methods than lists, and they're used when you don't expect or

7
00:00:32,740 --> 00:00:36,250
want a particular user to be able to change the sequence of items.

8
00:00:37,670 --> 00:00:42,860
While we don't manually define tuples, often we do see many Python functions actually return tuples

9
00:00:43,040 --> 00:00:49,850
when returning results recall, we call these items method on a dictionary and actually return tuples

10
00:00:49,850 --> 00:00:50,930
of key value pairs.

11
00:00:51,110 --> 00:00:52,940
Add the key first and then the value.

12
00:00:53,300 --> 00:00:58,220
This is a great use case for a tuple because you want to make sure that the user can't accidentally

13
00:00:58,220 --> 00:01:03,860
swap the value and the key confusing which one is which because it's in a tuple and it's immutable.

14
00:01:03,890 --> 00:01:06,470
You're always going to know, OK, that first item is key.

15
00:01:06,470 --> 00:01:08,270
That's second item is the value.

16
00:01:09,650 --> 00:01:14,870
Billions are going to be our basic building block for logic and control flow, allowing us to indicate

17
00:01:14,870 --> 00:01:16,730
if something is true or false.

18
00:01:17,090 --> 00:01:19,160
Let's explore these concepts in Python.

19
00:01:20,090 --> 00:01:22,040
OK, here we are inside the Python file.

20
00:01:22,460 --> 00:01:25,950
What I want to do is simply create a tuple if you want to create a list.

21
00:01:25,980 --> 00:01:29,300
Remember, that was square brackets like one two three.

22
00:01:29,540 --> 00:01:32,190
And those are the items in the list for a tuple.

23
00:01:32,320 --> 00:01:33,350
We'll say my tuple.

24
00:01:33,650 --> 00:01:36,770
This is similar to a list, except you use parentheses.

25
00:01:37,070 --> 00:01:41,780
So still, the same different types of items can go in there and then we can go ahead and print out

26
00:01:43,160 --> 00:01:43,820
my tuple.

27
00:01:44,750 --> 00:01:45,680
Save that change.

28
00:01:46,160 --> 00:01:47,770
Go ahead and run this.

29
00:01:47,780 --> 00:01:49,160
And now I see the tuple.

30
00:01:49,700 --> 00:01:53,900
Now look what's going to happen if I try to reassign an item in a list?

31
00:01:54,320 --> 00:02:03,380
For example, if I say my list grab item index zero and say it's equal to new and let's go ahead and

32
00:02:03,380 --> 00:02:05,690
then print out my list.

33
00:02:06,640 --> 00:02:07,570
Save that change.

34
00:02:07,690 --> 00:02:09,490
No, I'm still printing out the tuple as well.

35
00:02:10,210 --> 00:02:14,950
If I run that now, I see new two three and then one two three.

36
00:02:15,430 --> 00:02:16,620
So what's actually happening here?

37
00:02:16,630 --> 00:02:21,280
I'm just grabbing the item at index zero and this list and reassigning it to be new.

38
00:02:21,610 --> 00:02:22,900
No problem for a list.

39
00:02:23,230 --> 00:02:25,390
Now let's try the same thing for a tuple.

40
00:02:26,110 --> 00:02:30,940
So I'm going to switch this out to now say my tuple grab item at index zero and try to set it equal

41
00:02:30,940 --> 00:02:32,820
to new save that chains.

42
00:02:32,830 --> 00:02:33,610
Go ahead and run this.

43
00:02:34,870 --> 00:02:40,220
And now you get this error message, so it says sorry tuple object does not support item assignment.

44
00:02:40,240 --> 00:02:45,310
So as we mentioned, tuples are immutable, so once it's set to one two three, that's it.

45
00:02:45,310 --> 00:02:47,830
You can't go in and swap another item out.

46
00:02:48,250 --> 00:02:53,650
So you're going to want to use tuples when you don't want any user to have the ability to swap in items,

47
00:02:53,650 --> 00:03:00,130
which is why we see it so often used as a return mechanism or just a good way to report values back

48
00:03:00,130 --> 00:03:00,660
to a user.

49
00:03:00,670 --> 00:03:03,850
You say, here's a tuple, I'm not going to allow you to change it that way.

50
00:03:03,860 --> 00:03:05,980
We can avoid confusion later on.

51
00:03:06,490 --> 00:03:06,850
OK.

52
00:03:06,880 --> 00:03:11,050
So again, things like actual indexing is totally fine.

53
00:03:11,050 --> 00:03:17,350
So if you want to actually know the first item in a tuple like, say, index zero, that's totally OK.

54
00:03:17,440 --> 00:03:20,830
You just simply say Python Example pie here and notice it reports back.

55
00:03:20,840 --> 00:03:23,680
OK, item one is at index zero.

56
00:03:23,860 --> 00:03:25,240
Inside this tuple?

57
00:03:25,360 --> 00:03:26,110
No problem.

58
00:03:26,380 --> 00:03:27,190
Well, we can't do.

59
00:03:27,190 --> 00:03:29,080
Is the reassignment now.

60
00:03:29,080 --> 00:03:32,830
Again, as I mentioned, there's not going to be as many methods available on a tuple.

61
00:03:33,040 --> 00:03:37,660
I just want you to get familiar with the fact that parentheses are going to distinguish a tuple and

62
00:03:37,660 --> 00:03:39,520
a tuple is still a sequence of items.

63
00:03:40,090 --> 00:03:40,420
All right.

64
00:03:40,510 --> 00:03:41,750
So that is a tuple.

65
00:03:42,550 --> 00:03:47,260
The other data type I want you to be familiar with right now is a Boolean, which you may have heard

66
00:03:47,260 --> 00:03:48,130
in other languages.

67
00:03:48,460 --> 00:03:51,400
A Boolean is essentially just a true or false.

68
00:03:51,430 --> 00:03:57,880
For example, you can say a is true and then you can print out a.

69
00:04:01,240 --> 00:04:07,040
Save run that and you can see true, the other type of bullying is false.

70
00:04:07,120 --> 00:04:08,380
So that's pretty much it.

71
00:04:08,380 --> 00:04:10,450
It's either true or it's false.

72
00:04:10,930 --> 00:04:13,120
And there's not a whole lot we can do with them right now.

73
00:04:13,120 --> 00:04:18,010
But later on, when we learn about control flow, things like if statements, this is where you begin

74
00:04:18,010 --> 00:04:19,899
to add logic to your code.

75
00:04:19,930 --> 00:04:24,580
Things like, OK, if this is true, then do something else or if this is false.

76
00:04:24,850 --> 00:04:26,230
Go ahead and do something.

77
00:04:26,770 --> 00:04:30,670
And for instance, you're going to see these kind of things and we learn about comparison operators,

78
00:04:30,670 --> 00:04:31,330
for example.

79
00:04:31,720 --> 00:04:37,150
I'm not saying, OK, Prince is one greater than two.

80
00:04:37,240 --> 00:04:39,250
So this is actually a comparison operation.

81
00:04:39,490 --> 00:04:40,810
I'm saying compare one.

82
00:04:40,840 --> 00:04:42,370
Is it greater than two?

83
00:04:43,000 --> 00:04:45,010
So let's go ahead and save that and see the result.

84
00:04:45,580 --> 00:04:48,040
This returns back a boolean false.

85
00:04:48,490 --> 00:04:54,370
Now, let's say, is one less than to save that change.

86
00:04:54,550 --> 00:04:58,270
Go ahead and run this and this returns back.

87
00:04:58,270 --> 00:04:58,600
True.

88
00:04:59,080 --> 00:05:04,510
So we can already see that there's some idea of comparing two different data types within Python to

89
00:05:04,510 --> 00:05:06,670
get back a boolean true or false.

90
00:05:07,180 --> 00:05:07,930
Now that's it.

91
00:05:07,930 --> 00:05:10,690
Just very brief overview of Tuples and Bulletin's.

92
00:05:10,960 --> 00:05:13,000
We'll be using those later on in our code.

93
00:05:13,360 --> 00:05:13,630
OK.

94
00:05:13,960 --> 00:05:14,290
Thanks.

95
00:05:14,290 --> 00:05:15,340
And I'll see you at the next lecture.

