-: Hi, guys, and welcome back.
In this video, we're going to learn
about the in keyword in Python.
The in keyword is something we can use
to check for membership,
whether one thing is inside a list
or a tuple or a set.
Let's get started.
I'll have a list of friends,
which contains Rolf, Bob, and Jen.
And then we can very easily print
whether Jen is in friends.
And this is going to check whether the string Jen
is one of the members in this list.
So if we save that and run it,
you'll see that we get back true.
Now let's say that we have a set
of the movies we've recently watched.
I'm using a set here
because movies are unique, so you can't have duplicates
and having a set actually helps you prevent duplication.
In addition, the movies that we've watched
in this case don't have any specific order.
So we don't care about the order,
and therefore a set is a perfect structure
to put these movies into.
Then we are going to ask the user
for a movie they've watched recently.
And finally, we're going to print
whether that movie is in our movies watched.
If we run this,
then you'll see that if we type The Matrix, you get true,
but if you type Monty Python,
then you'll get false.
The in keyword works in sequences
like lists, tuples, sets.
It also works in strings, actually,
so you can check whether a string
is inside another string, such as a substring.
For example, R-I-X would be in The Matrix.
So you can do checks like that, as well, if you want.
Let's move on to the next video
where we're gonna learn how to use if statements
with this syntax here
so that we can create even more powerful programmes.
I'll see you there.