Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Check the Beginning of a String (Solution)

00:00 The task here was to check the result of .startswith() with "be" on four strings.

00:13 First one is "Becomes". String two was "becomes" in lowercase. String three is "BEAR" in all uppercase. String four is mixed case and starting off with two whitespaces and then lowercase b, uppercase E, and then we continue in lowercase writing beautiful.

00:44 So those are the four strings, and now we’re going to check what happens when we call .startswith("be") on each of them. So I will type string1,

00:55 and then .startswith("be"). And this results in False. And you can reason about it. If you expect this to be True, then keep in mind that the uppercase "B" and the lowercase "b" are two different characters, which is why this string1 does not start with "be".

01:15 The next one, however, does, so string2.startswith("be") should return True. should return True.

01:21 Does string3.startswith("be")? What do you think this is going to return?

01:29 It’ll be False because both of these letters are in uppercase, which makes them different characters than the "be". And finally, we have string4.startswith("be"),

01:44 and there’s a couple of reasons why this is going to be False. First is that the first two characters are actually whitespace characters. So this is not at all as lowercase "be", and even if you would get rid of these two whitespaces, it would still be False because while the first character after the white spaces is a lowercase "b", the second one is an uppercase "E".

02:05 All right, so the results are False, True, False, False for the four strings.

Become a Member to join the conversation.