1
00:00:04,660 --> 00:00:10,580
Alright so before we finish with conditions,
I want to look now at in and not in.

2
00:00:10,580 --> 00:00:13,850
There are two uses of in and we're
going to be seeing it used with a for

3
00:00:13,850 --> 00:00:18,650
loop later. Here though, we're concentrating
on using in as a condition. So we need a

4
00:00:18,650 --> 00:00:22,820
new Python file for this one and I'm still
on the same project. I'm going to call

5
00:00:33,280 --> 00:00:36,530
So in is used in sequences and we'll make much more use of

6
00:00:36,530 --> 00:00:40,640
it when we come to look at lists in a
later section in the course. One sequence

7
00:00:40,640 --> 00:00:44,510
that we have used, though, is a string - a
sequence of characters. So let's type in

8
00:00:44,510 --> 00:00:56,500
some code: parrot is equal to Norwegian
Blue. Line 3, letter equals input

9
00:00:56,500 --> 00:01:04,800
parenthesis double quotes enter a
character colon and a space there.

10
00:01:04,800 --> 00:01:15,340
Line 5, if letter in parrot colon print
parenthesis double quotes, left and right

11
00:01:15,340 --> 00:01:22,180
curly braces in the double quotes, is in,
left and right curly braces double quote

12
00:01:22,180 --> 00:01:28,700
dot format parentheses letter comma
parrot and two right parentheses.

13
00:01:28,700 --> 00:01:34,640
Then on the next line else colon. On the line
after that print parenthesis and in

14
00:01:34,640 --> 00:01:39,140
double quotes, I don't need that letter.

15
00:01:41,840 --> 00:01:46,960
So we'll run that program. I'm gonna start by
entering the letter a when asked for

16
00:01:46,969 --> 00:01:53,990
a character here - a is in Norwegian Blue. So
that assigns the name letter to a string

17
00:01:53,990 --> 00:01:58,600
value a and line 5 checks if the
letter appeared in the parrot string.

18
00:01:58,600 --> 00:02:02,840
a does appear in Norwegian blue so their
condition evaluates to true, and we get

19
00:02:02,840 --> 00:02:06,920
the message a is in Norwegian Blue printed
out, as you can see. So we're going to run

20
00:02:06,920 --> 00:02:10,880
the program again. This time I'm going to
try a letter that doesn't appear in the

21
00:02:10,880 --> 00:02:17,000
string, so I'm going to enter a z. I
don't need that letter, is output.

22
00:02:17,000 --> 00:02:21,020
When you enter the input remember that
string comparisons are case-sensitive.

23
00:02:21,020 --> 00:02:25,420
If you enter a capital A it won't be found
in the string, and you can also check for

24
00:02:25,420 --> 00:02:31,240
longer sequences. So if we run the
program again now, I'm going to enter

25
00:02:31,240 --> 00:02:38,260
blue with a capital B and press Enter.
Blue is in Norwegian blue.

26
00:02:38,260 --> 00:02:43,940
If you try that with blue all in lowercase it won't
be found, and I'll just confirm that,

27
00:02:45,720 --> 00:02:51,400
showing indeed that in is case-sensitive.
Alright, so as well as checking if

28
00:02:51,400 --> 00:02:56,600
something is in a sequence we can test
if it isn't, and we do that using not in.

29
00:02:56,600 --> 00:03:07,360
So we're going to create a new Python
file here and we'll call it notin.

30
00:03:07,360 --> 00:03:14,680
Start by typing activity is equal to, then in
double quote input parenthesis and in

31
00:03:14,680 --> 00:03:22,900
double quotes, What would you like to do
today? A space there before the double

32
00:03:22,900 --> 00:03:28,090
quote and then the right parenthesis.
Then on line 3, if and in double quotes

33
00:03:28,090 --> 00:03:41,060
cinema in lowercase not in activity :
print But I want to go to the cinema

34
00:03:41,060 --> 00:03:47,580
and then the double quote and the right
parenthesis. If you run this program now,

35
00:03:47,820 --> 00:03:53,020
and I'm going to type I want to learn Python.

36
00:03:54,900 --> 00:03:58,680
We get the output, But I want to go to
the cinema. Because the string cinema

37
00:03:58,680 --> 00:04:02,860
isn't in I want to learn Python, the
boolean expression evaluates to true.

38
00:04:02,860 --> 00:04:08,050
Remember that we're using not in here. So I've mentioned a few times now, that string

39
00:04:08,050 --> 00:04:13,660
comparisons are case sensitive and this
can cause confusion for our users if we

40
00:04:13,660 --> 00:04:19,440
don't handle it correctly. To see what I
mean I'm going to run the program again,

41
00:04:19,440 --> 00:04:24,680
and I'm going to enter the text I want
to go to the cinema, but I'm going to use a

42
00:04:24,680 --> 00:04:29,300
capital C for cinema, and we still get
the message But I want to go to the cinema.

43
00:04:29,300 --> 00:04:32,980
Now that's a bit confusing, or
could be, for users of your programs.

44
00:04:32,980 --> 00:04:35,780
Fortunately though, that's an easy thing
to deal with.

45
00:04:35,780 --> 00:04:39,220
Python strings have a load of useful
functions and one of them converts a

46
00:04:39,220 --> 00:04:44,100
string to lowercase. In fact there are
two functions that do a similar thing.

47
00:04:44,100 --> 00:04:49,100
I'll show you how to find them all in a
moment but firstly, though, let's modify our program slightly.

48
00:04:49,100 --> 00:04:51,640
And what I'm going to do
is, where it's got not in activity after

49
00:04:51,640 --> 00:04:57,260
activity, I'm going to put .casefold.

50
00:04:57,260 --> 00:05:01,880
So the casefold function converts a
string to lowercase, but it handles

51
00:05:01,880 --> 00:05:05,420
different character sets better than
just converting to lower case would.

52
00:05:05,420 --> 00:05:08,920
Unless you're familiar with languages like
German, they have different lowercase

53
00:05:08,920 --> 00:05:12,960
representations of some letters, you
probably wouldn't be aware of the problem.

54
00:05:12,960 --> 00:05:16,200
But don't worry, just remember to
use casefold rather than lower case

55
00:05:16,200 --> 00:05:21,460
when you want to compare strings. 
Alrighty, so if I run the code again now,

56
00:05:21,460 --> 00:05:25,960
and this time we're going to type the
same thing in, I want to go to the cinema,

57
00:05:25,960 --> 00:05:30,760
with a  capital C again. We don't get that
confusing message anymore because the

58
00:05:30,760 --> 00:05:35,200
match has now clearly worked using casefold.
Alright so I'm going to finish this

59
00:05:35,200 --> 00:05:39,680
video by having a look at all the
functions that the Python string class provides.

60
00:05:39,680 --> 00:05:43,690
Let's open a browser and I'll paste
in the link, and this link is in the

61
00:05:43,690 --> 00:05:47,980
resources section of this video. Alright,
so you can scroll down to the string method

62
00:05:47,980 --> 00:05:51,970
section, or what we can do here to save a
bit of time, we can just do a search.

63
00:05:51,970 --> 00:05:56,140
I'm gonna search for string methods. There's
string methods. I can just click on this,

64
00:05:56,140 --> 00:06:02,620
well it's just down here anyway. So I'll close
down my search. You can see them on screen.

65
00:06:02,620 --> 00:06:06,360
So this is an alphabetical list of all the
methods that the string class provides.

66
00:06:06,360 --> 00:06:09,760
You can see there that casefold
is the second one there, and you

67
00:06:09,760 --> 00:06:13,090
can read a description there of what it
actually does. Now I wouldn't suggest

68
00:06:13,090 --> 00:06:16,600
trying to memorize all these methods but
it is worth spending some time reading

69
00:06:16,600 --> 00:06:20,470
about them. When you need to do something
such as checking if a string contains

70
00:06:20,470 --> 00:06:24,800
only digits, for example, you'll remember
that there's a method to do that.

71
00:06:24,800 --> 00:06:28,020
You won't remember what it's called unless
you've used it a few times, but you'll

72
00:06:28,030 --> 00:06:31,420
know where to go to find it. We'll be
using quite a few of these methods

73
00:06:31,420 --> 00:06:34,840
through the course so you'll get a lot
of practice at using them.

74
00:06:34,840 --> 00:06:38,880
Alright, so we've covered quite a bit about
if statements and conditions. Before we move

75
00:06:38,890 --> 00:06:42,520
on to start looking at loops, the next
video is going to be a challenge to let

76
00:06:42,520 --> 00:06:47,880
you practice some of what you've learnt
so far. See you in the next video.

