1
00:00:01,140 --> 00:00:08,040
In this lecture, I'm going to talk about the three types of sequences that are available in Python

2
00:00:08,520 --> 00:00:16,260
sequences, done types that allow you to store multiple items under the same variable name and Python,

3
00:00:16,260 --> 00:00:21,420
both see Python and Micro Python provided three types of sequences.

4
00:00:21,450 --> 00:00:26,290
We have lists, tables and ranges in this lecture.

5
00:00:26,310 --> 00:00:33,570
I'll show you how to use all three in a basic way so that you are prepared to use them in the lectures

6
00:00:33,570 --> 00:00:35,190
that are coming up later in this course.

7
00:00:35,970 --> 00:00:37,200
Let's begin with lists.

8
00:00:37,200 --> 00:00:40,320
So lists are mutable sequences.

9
00:00:40,680 --> 00:00:45,330
Mutable means that once you create a list, you can change it later.

10
00:00:45,340 --> 00:00:53,280
You can edit individual items in a list and typically we use them to store items that are all of the

11
00:00:53,280 --> 00:00:54,110
same kind.

12
00:00:54,120 --> 00:01:01,140
So you can have a list, for example, that store integers or a list that contains floating point numbers

13
00:01:01,140 --> 00:01:02,100
or strings.

14
00:01:03,240 --> 00:01:05,610
Tuples, on the other hand, are immutable.

15
00:01:06,060 --> 00:01:12,150
There are still sequences we can store multiple items in a temple, but unlike a list, you can't make

16
00:01:12,150 --> 00:01:15,660
a change to a tuple once you create it again.

17
00:01:15,660 --> 00:01:22,080
Unlike a list, though, in a table, typically you can store data items of different types.

18
00:01:22,110 --> 00:01:25,980
So you can have a table that contains numbers and strings.

19
00:01:25,980 --> 00:01:27,000
No problem at all.

20
00:01:27,630 --> 00:01:37,380
Finally, Rangers' is a type of sequence that contains numbers and just like a tuple, it is immutable

21
00:01:37,620 --> 00:01:41,160
and we use ranges to count in loops.

22
00:01:41,160 --> 00:01:44,880
For example, is the most common case use for a range.

23
00:01:45,600 --> 00:01:47,820
So let's have a look at some examples.

24
00:01:47,820 --> 00:01:55,260
And these examples, again, are borrowed from the documentation, which is where you can go to do more

25
00:01:55,260 --> 00:01:56,710
reading about each one of those.

26
00:01:56,730 --> 00:01:58,930
So is the invitation for lists.

27
00:01:59,550 --> 00:02:01,940
These are the documentation for tables.

28
00:02:01,950 --> 00:02:08,430
And finally, you've got the range function here that we use to generate range sequences.

29
00:02:09,270 --> 00:02:09,540
All right.

30
00:02:09,540 --> 00:02:13,620
So let's begin with lists to create a list.

31
00:02:13,740 --> 00:02:20,040
Just going to copy so that if there save myself from typing and making typing mistakes.

32
00:02:20,340 --> 00:02:25,740
So this is how you can quickly create other ways as well, as you can see in the documentation.

33
00:02:25,740 --> 00:02:32,460
But in most cases will be creating a list like this is a variable name is always the assignment operator.

34
00:02:32,460 --> 00:02:39,680
And then we've got the square brackets that contain the items that we are storing in a list.

35
00:02:39,690 --> 00:02:43,560
In this case, as you can see, we've got a list of strings.

36
00:02:44,160 --> 00:02:47,520
We submit this command and now we have a list.

37
00:02:48,120 --> 00:02:51,960
We can have a look at the contents of the list by just calling its name.

38
00:02:52,290 --> 00:02:59,040
And you can see again is denoted by the open and closed square brackets and then the items inside the

39
00:02:59,040 --> 00:02:59,460
list.

40
00:02:59,790 --> 00:03:10,350
I can have a list of integers, for example, in TS, and it's exactly the same way, except that now

41
00:03:10,350 --> 00:03:11,400
we've got the numbers.

42
00:03:11,880 --> 00:03:12,690
Let's make it four.

43
00:03:13,380 --> 00:03:17,190
And here's the list tab for code completion.

44
00:03:17,190 --> 00:03:18,720
And these are the integers.

45
00:03:19,710 --> 00:03:25,340
We can also do things such as list the integers in reverse order.

46
00:03:25,350 --> 00:03:37,410
So let's say a list of letters and I can say that give me a list that is sorted in reverse, reverse

47
00:03:37,410 --> 00:03:37,830
order.

48
00:03:40,290 --> 00:03:43,890
And it would look like this just printed out now.

49
00:03:44,070 --> 00:03:50,280
So internally, Python has rearranged the items in this list of letters and now can print it out.

50
00:03:50,550 --> 00:03:53,270
And you can see that it's printed out in reverse order.

51
00:03:53,500 --> 00:03:58,280
You can find more information about this and the various methods that are available here.

52
00:03:58,770 --> 00:04:04,710
I'm taking some examples out of this documentation and also show you one more place.

53
00:04:05,280 --> 00:04:12,360
So the conclusion that shows the functions that are available for a list in the Python three library

54
00:04:12,360 --> 00:04:18,120
standard types documentation, then you can see that this is one of the example operators that he can

55
00:04:18,120 --> 00:04:19,140
use of functions.

56
00:04:19,150 --> 00:04:26,890
And the one that I've used is stored and I turned reverse into true so I can give me the listing or

57
00:04:26,980 --> 00:04:29,940
items of the list in reverse order.

58
00:04:30,150 --> 00:04:31,740
I can do the same thing for the numbers.

59
00:04:31,740 --> 00:04:34,170
Of course I can say list.

60
00:04:36,090 --> 00:04:48,690
Of integers and just a short reverse order like this, and now the numbers come out from top to bottom

61
00:04:48,690 --> 00:04:49,920
review, highest and lowest.

62
00:04:50,220 --> 00:04:57,100
I can also retrieve individual items out of a list by using the square bracket notation.

63
00:04:57,100 --> 00:05:04,890
So, for example, if I want to see the second item in this list, which is index zero and one, then

64
00:05:04,890 --> 00:05:12,360
I can call that like this list of letters, open square bracket index one and close the parentheses.

65
00:05:12,360 --> 00:05:14,240
And that will give me a.

66
00:05:15,670 --> 00:05:21,520
So this is the second item in this area, you can click on the area as well, and the object inspector

67
00:05:21,520 --> 00:05:28,390
will also give you an index number and the value stored at that index number for go for the same thing.

68
00:05:28,400 --> 00:05:38,440
But now index to as you see here, that's a and most getting a ratio in the exact same thing happens

69
00:05:38,440 --> 00:05:47,960
with the list of the numbers and lets you do that exercise or least clear up and move on to tuples and

70
00:05:48,250 --> 00:05:54,370
to create a tuple just copy and paste the table that I've already created here.

71
00:05:54,370 --> 00:05:59,320
And you can see that I'm using the same method, essentially, as with every variable of the name of

72
00:05:59,320 --> 00:06:00,760
the variable, the assignment operator.

73
00:06:00,770 --> 00:06:07,480
But now instead of square brackets that I'm using for the lists, I'm using a parentheses, open and

74
00:06:07,480 --> 00:06:08,440
close parentheses.

75
00:06:08,950 --> 00:06:15,310
And inside, as far as the items of the table are concerned, you can see heterogeneous items.

76
00:06:15,310 --> 00:06:22,990
I'm using integers and strings, floating point numbers, and that is no problem at all for a tuple

77
00:06:23,470 --> 00:06:24,340
I can.

78
00:06:26,060 --> 00:06:31,800
Print out the contents of the table like this on the show, and you can see that it comes back with

79
00:06:31,800 --> 00:06:35,390
the parentheses instead of the square brackets.

80
00:06:35,390 --> 00:06:43,070
And that's how, you know, whether you're working with a table or with a list is by looking at the

81
00:06:43,070 --> 00:06:51,080
types of brackets that are used, whether they are parentheses or square brackets, in order to retrieve

82
00:06:51,080 --> 00:06:57,200
an item from a table and using the same notation as I did earlier with the list.

83
00:06:57,200 --> 00:06:59,450
And I'm going to use this time square brackets.

84
00:06:59,480 --> 00:07:02,300
So this is the thing that sometimes can be confusing.

85
00:07:02,630 --> 00:07:09,620
So, for example, if I want to print out, just going to click on the table, go and it appears on

86
00:07:09,620 --> 00:07:16,010
the inspector I to print out the let's say the.

87
00:07:18,330 --> 00:07:24,630
Item number one, index number one from the tuple, then I use the square bracket to indicate that and

88
00:07:24,630 --> 00:07:29,010
hit enter and I'm getting a fair go for.

89
00:07:32,090 --> 00:07:41,210
Indexed to that will give me the number to out, since that's what's stored in index to there's more

90
00:07:41,210 --> 00:07:46,100
documentation about how those here in Python, three libraries, standard types, and you can see more

91
00:07:46,100 --> 00:07:48,050
information about how to use tuples here.

92
00:07:48,500 --> 00:07:48,880
All right.

93
00:07:48,890 --> 00:07:52,180
Now, the last one that I want to show you is the range.

94
00:07:52,190 --> 00:07:59,030
So the range to said we use that there's a function called range that creates a sequence of numbers

95
00:07:59,570 --> 00:08:05,630
and the documentation for the range of the leadership right here in this tab.

96
00:08:05,720 --> 00:08:12,670
So here's some examples of how you can use it to the function range if it requires at least one parameter.

97
00:08:12,740 --> 00:08:18,110
But you can have more than one error in this example here has got two parameters and there's one more

98
00:08:18,530 --> 00:08:19,630
down here.

99
00:08:19,640 --> 00:08:21,970
Believe it's not listed here.

100
00:08:21,980 --> 00:08:23,030
I'm going to give you an example.

101
00:08:23,270 --> 00:08:31,280
We can have three parameters, but the source documentation and you can look at it right here, we can

102
00:08:31,280 --> 00:08:41,270
see the range function and there are three parameters that is capable of receiving as a start stop.

103
00:08:41,270 --> 00:08:45,490
And then if you want, you can define a step which can be negative or positive.

104
00:08:46,040 --> 00:08:51,460
So let's have a look at a few examples here of how to use ranges.

105
00:08:51,830 --> 00:08:55,310
So first of all, I'm is going to create a simple range.

106
00:08:56,100 --> 00:09:01,520
It's a sequence of numbers that count from zero to one.

107
00:09:02,420 --> 00:09:03,440
Let's check it out.

108
00:09:03,860 --> 00:09:04,990
Check out its contents.

109
00:09:05,000 --> 00:09:08,360
That is, you can see zero to 10.

110
00:09:08,900 --> 00:09:17,030
And if I click on the object inspector, that's what comes up right here for use the list command and

111
00:09:17,030 --> 00:09:24,220
ask Python to list the contents of this variable range zero to 10.

112
00:09:24,770 --> 00:09:28,700
Then you'll see the actual components of this range.

113
00:09:29,210 --> 00:09:33,800
You can see called square brackets, which means that there is a list in the square.

114
00:09:33,800 --> 00:09:39,640
I was able to use the list command to show me the actual items in this list.

115
00:09:40,250 --> 00:09:47,930
So the thing to take away from this is that the range function allows us to quickly create lists of

116
00:09:47,930 --> 00:09:48,480
numbers.

117
00:09:49,130 --> 00:09:55,460
So if you just use a single parameter, then the list of numbers that you get starts from zero and goes

118
00:09:55,460 --> 00:10:00,330
all the way to the number just before the number that you have specified in the function.

119
00:10:00,740 --> 00:10:04,300
So it's zero indexed and therefore is going to go up to nine.

120
00:10:04,970 --> 00:10:15,050
The variation is to have a list such as this where we use the range function, but now we got the two

121
00:10:15,050 --> 00:10:15,700
parameters.

122
00:10:15,710 --> 00:10:20,270
The first number is the starting number and then we got the last number.

123
00:10:20,720 --> 00:10:21,770
But the ending number.

124
00:10:22,400 --> 00:10:33,620
And if you use the list function to check the contents of this list, you'll see that it starts from

125
00:10:33,620 --> 00:10:37,220
five inclusive and goes to nine not inclusive.

126
00:10:38,420 --> 00:10:44,900
The last variation of the range function that I want to show you is the one that used this, the third

127
00:10:44,900 --> 00:10:46,410
parameter for the step.

128
00:10:46,790 --> 00:10:50,650
So in this case, we've got range zero to 50, step five.

129
00:10:51,320 --> 00:10:59,660
It's going to create a list that starts from zero finishes at forty nine, but count at five point thirty

130
00:10:59,660 --> 00:11:00,110
five.

131
00:11:00,440 --> 00:11:03,530
That will look like this.

132
00:11:05,510 --> 00:11:06,470
This range.

133
00:11:08,050 --> 00:11:08,600
All right.

134
00:11:08,740 --> 00:11:12,710
Zero, five, 10, 15 and so on, up to forty five.

135
00:11:12,970 --> 00:11:14,220
You can also go negative.

136
00:11:14,680 --> 00:11:25,840
So I'm going to go to modify this is going to be from 50 to zero, Steph, minus five and five.

137
00:11:26,290 --> 00:11:27,360
Use a minus sign here.

138
00:11:28,090 --> 00:11:32,130
So there's going to be five zero and minus five.

139
00:11:33,070 --> 00:11:38,350
And let's give a list to this range, 50 to zero.

140
00:11:39,880 --> 00:11:41,130
And it looks like this.

141
00:11:41,140 --> 00:11:44,680
So counting down of it can go down to negative numbers.

142
00:11:44,680 --> 00:11:44,940
Maybe.

143
00:11:44,950 --> 00:11:45,940
Let's try this.

144
00:11:48,550 --> 00:11:50,650
Let's go up to minus 10.

145
00:11:52,840 --> 00:11:59,230
You saw the mistake here that should be minus 10 and.

146
00:12:00,680 --> 00:12:08,590
Let's make that 10:00 for the new range and let's print it out.

147
00:12:15,940 --> 00:12:20,760
We can have negative numbers, so all this is going to be very useful.

148
00:12:20,800 --> 00:12:23,230
You can see in.

149
00:12:24,760 --> 00:12:33,850
This example here where we can use the range inside a full loop in order to create this loop based on

150
00:12:33,850 --> 00:12:39,550
this range is something that will be using quite frequently in the lectures that are coming up.

151
00:12:41,180 --> 00:12:43,990
OK, so that's about the three types of sequences in.
