Person X (Solution)
00:01
I’m going to collect my name into the my_name
variable, and that should be a tuple that I create by using the tuple()
function and putting in my name.
00:11 My name is Martin. Your name may be Martin or something else.
00:17 Of course, if you put in your own name, this is going to look a little different than here, but feel free to use my name if you want to get the exact same results.
00:25 Next one is checking whether the character X
00:29
is in the my_name
tuple. Well, let’s look at the my_name
tuple first. Actually, my_name
looks like that it’s a tuple that contains a bunch of strings that each represent one character of my name.
00:42 All right, and now I want to check, is the character X in my name? I would be surprised if that was true. That would be news to me. Okay, it’s not true. There is no X in my name.
00:54 And then finally, I want to create a copy of the tuple that excludes the first letter. So I want to take all the characters starting from index one, but not the character at index zero.
01:07
And I can do that by using the variable my_name
that I’ve defined before, then opening up square brackets to use slice notation. And I’m going to start at index one, not at index zero, which is going to be the first letter of my name, but at index one, which is going to be the second letter.
01:23 And then I go all the way to the end and I can do that by putting the colon and then omitting the second index. That just means go all the way to the end,
01:32
and that’s going to create a new tuple that contains the characters "a", "r", "t", "i", "n"
. All right, note that running this line of code created a new tuple, but I didn’t save that tuple to a variable.
01:47 If you wanted to continue to work with the tuple that’s the result of the slicing operation, then you’d have to assign it to a variable. But as this is the end of the exercise, I’ll keep moving on to the next one.
Become a Member to join the conversation.