1
00:00:04,500 --> 00:00:09,309
Contining with our strings2 program, I'm
going to delete everything except the

2
00:00:09,309 --> 00:00:15,320
definition of parrot on line 3,
and also the first slice.

3
00:00:15,320 --> 00:00:17,760
The start, stop and step values in a slice

4
00:00:17,760 --> 00:00:21,039
can also be negative. So let's add some code on line 7,

5
00:00:21,039 --> 00:00:27,880
print then left parentheses parrot
left square bracket -4:2

6
00:00:27,880 --> 00:00:32,590
right square bracket then right
parenthesis. Now if we run this we'll find

7
00:00:32,590 --> 00:00:36,660
that this actually doesn't print out
anything. So it doesn't print the two

8
00:00:36,660 --> 00:00:40,920
characters starting 4 in from the end
of the string, and it's printing nothing, as

9
00:00:40,930 --> 00:00:45,250
I mentioned, and that's because you can't
go backwards from the starting position.

10
00:00:45,250 --> 00:00:52,340
So instead we'd have to write that as
-4, which we've got, but then -2,

11
00:00:52,340 --> 00:00:56,100
and as a comment that should give us Bl.

12
00:00:56,100 --> 00:00:57,860
As another example print

13
00:00:57,869 --> 00:01:04,299
parentheses parrot again, then left square
bracket -4:12 right square

14
00:01:04,299 --> 00:01:09,700
bracket right parenthesis, then that will
actually give us the same thing. So if we

15
00:01:09,700 --> 00:01:18,130
run this, you can see we've got Bl in both
cases there. So the first one, on line 7,

16
00:01:18,130 --> 00:01:24,460
that prints from index -4 and
that's B, capital B, up to but not

17
00:01:24,460 --> 00:01:28,360
including the second-to-last character
in the string, which is u.

18
00:01:28,800 --> 00:01:34,299
Now the second example, on line 8, prints the same
thing but this time it's interpreted as

19
00:01:34,300 --> 00:01:40,760
from index -4, up to but not
including index position 12.

20
00:01:40,760 --> 00:01:43,860
So spend some time experimenting with negative indices.

21
00:01:43,869 --> 00:01:47,770
There's nothing tricky about them.
they're just counting from the end of

22
00:01:47,770 --> 00:01:52,450
the string, instead of from the beginning.
Make sure you can reproduce all the

23
00:01:52,450 --> 00:01:57,340
slices from the last video, using
negative indices. I'll do the one on line 5

24
00:01:57,340 --> 00:02:01,210
just to get you started,
and we'll do that just immediately under

25
00:02:01,210 --> 00:02:08,110
line 5. So the negative version of that
would be print parentheses parrot square

26
00:02:08,110 --> 00:02:14,799
bracket -14:-8. Then we want
our right to square bracket right

27
00:02:14,799 --> 00:02:17,470
parenthesis and that should give us the same result.

28
00:02:17,470 --> 00:02:21,970
So let's just run that to make sure that it
works, and you can see we've got Norweg

29
00:02:21,970 --> 00:02:26,650
outputted twice. So again, make sure
you go through and reproduce all the

30
00:02:26,650 --> 00:02:30,400
slices from the last video, using
negative indices, to really make sure

31
00:02:30,400 --> 00:02:33,730
that you understand how they work. But
also, with that said, create your own

32
00:02:33,730 --> 00:02:35,940
strings and practice on them as well.

33
00:02:35,940 --> 00:02:39,700
In the next video, we'll see how to use a step in our slices.

34
00:02:39,700 --> 00:02:42,700
See you in the next video.

