1 00:00:08,030 --> 00:00:12,950 So far we've created sequences like lists, strings and tuples, 2 00:00:12,950 --> 00:00:14,695 just by declaring literals, 3 00:00:14,695 --> 00:00:16,050 just like on line one, 4 00:00:16,050 --> 00:00:18,150 how we declared this list through. 5 00:00:18,150 --> 00:00:22,540 Another way to create them is through concatenation and repetition. 6 00:00:22,540 --> 00:00:28,090 Concatenate takes two sequences and adds them together to form one long sequence. 7 00:00:28,090 --> 00:00:29,935 So, here on line three, 8 00:00:29,935 --> 00:00:34,070 we say print out the value of this sequence with two items, 9 00:00:34,070 --> 00:00:40,825 one and two, concatenated with this other sequence with two other items, three and four. 10 00:00:40,825 --> 00:00:45,560 Now, the result of this overall expression is 11 00:00:45,560 --> 00:00:50,120 going to be a new list that has all of those items kind of squished together. 12 00:00:50,120 --> 00:00:52,820 So, it's going to be a new list with items one, 13 00:00:52,820 --> 00:00:56,895 two, three, four. So, let's run. 14 00:00:56,895 --> 00:00:59,810 We can see that our new list just has items one, 15 00:00:59,810 --> 00:01:01,625 two, three and four. 16 00:01:01,625 --> 00:01:04,070 So, that's concatenation. 17 00:01:04,070 --> 00:01:08,420 We can also take an existing list like fruit and 18 00:01:08,420 --> 00:01:12,560 concatenate it with a list that we create on the file like right here. 19 00:01:12,560 --> 00:01:15,950 So, here we have a list of strings in fruit. 20 00:01:15,950 --> 00:01:18,905 So, we have apple, orange, banana, and cherry. 21 00:01:18,905 --> 00:01:22,685 In here, we take that list and concatenate it 22 00:01:22,685 --> 00:01:26,970 with another list with numbers six, seven, eight, nine. 23 00:01:26,970 --> 00:01:29,640 When we do that, then we're going to get apple, 24 00:01:29,640 --> 00:01:32,970 orange, banana, cherry, six, seven, eight, nine. 25 00:01:32,970 --> 00:01:35,415 Let's run to be sure. 26 00:01:35,415 --> 00:01:39,620 You can see that these two lists were concatenated. 27 00:01:39,620 --> 00:01:41,600 In addition to concatenation, 28 00:01:41,600 --> 00:01:43,235 we can also do repetition, 29 00:01:43,235 --> 00:01:46,525 or repeating a list any number of times. 30 00:01:46,525 --> 00:01:50,720 Whereas concatenation uses the addition or plus operator, 31 00:01:50,720 --> 00:01:54,830 repetition uses the star or multiplication operator. 32 00:01:54,830 --> 00:01:58,175 So, if we have this list that has one item, 33 00:01:58,175 --> 00:02:00,260 that item being the integers here, 34 00:02:00,260 --> 00:02:04,850 and we say repeat this item four times by saying, 35 00:02:04,850 --> 00:02:08,030 the list and then multiply it by four, 36 00:02:08,030 --> 00:02:12,485 then we get a new list that repeats the contents of this list four times. 37 00:02:12,485 --> 00:02:15,860 So we should get a list that has zero four times. 38 00:02:15,860 --> 00:02:18,125 You see that's exactly what we get. 39 00:02:18,125 --> 00:02:21,080 If this list had more than one item in it, so, 40 00:02:21,080 --> 00:02:25,120 let's suppose this list had zero and one as items, 41 00:02:25,120 --> 00:02:29,395 then both of those items get repeated four times as well. 42 00:02:29,395 --> 00:02:32,110 So, you can see our new list has zero, 43 00:02:32,110 --> 00:02:35,105 one, zero, one, zero, one. 44 00:02:35,105 --> 00:02:39,395 Just like before, we can actually mix up different types. 45 00:02:39,395 --> 00:02:43,350 So, we can say something like, print out fruit, 46 00:02:43,560 --> 00:02:50,355 plus the list one and multiply that four times. 47 00:02:50,355 --> 00:02:53,220 So, that's going to take apple, orange, banana, 48 00:02:53,220 --> 00:02:56,490 cherry, and then add one to that list. 49 00:02:56,490 --> 00:02:58,980 So, apple, orange, banana, cherry, one. 50 00:02:58,980 --> 00:03:02,620 It's going to repeat that four times. 51 00:03:02,690 --> 00:03:06,720 So you see apple, orange, banana, cherry, 52 00:03:06,720 --> 00:03:08,460 one, apple, orange, banana, 53 00:03:08,460 --> 00:03:10,890 cherry, one, and so on. 54 00:03:10,890 --> 00:03:16,010 So, one thing to note about concatenation and repetition is that they follow 55 00:03:16,010 --> 00:03:20,735 the exact same order of operations as addition, multiplication, and subtraction. 56 00:03:20,735 --> 00:03:24,260 So here, we put parentheses to say that we want to 57 00:03:24,260 --> 00:03:28,025 do the concatenation before we do the repetition. 58 00:03:28,025 --> 00:03:30,725 If we had actually left out the parentheses, 59 00:03:30,725 --> 00:03:38,505 then we would get the list fruit plus the list one repeated four times. 60 00:03:38,505 --> 00:03:41,630 So, we would get an entirely different result. 61 00:03:41,630 --> 00:03:44,840 So, let's go through this in code lens. 62 00:03:44,840 --> 00:03:48,785 So, suppose that we create that same list that we created last time, 63 00:03:48,785 --> 00:03:52,350 so we have fruit as a list, apple, orange, banana, 64 00:03:52,350 --> 00:03:55,195 cherry, If I stepped forward, 65 00:03:55,195 --> 00:04:00,020 and you'll see that fruit here gets assigned to a list with item zero, 66 00:04:00,020 --> 00:04:02,635 item one, two, three. 67 00:04:02,635 --> 00:04:06,225 Then, if I create a new list of numbers, 68 00:04:06,225 --> 00:04:08,545 so those numbers being six and seven, 69 00:04:08,545 --> 00:04:11,420 then we create a new list in the global frame. 70 00:04:11,420 --> 00:04:17,705 So, we say numlist is assigned to a list with six and seven in it. 71 00:04:17,705 --> 00:04:21,350 Now, if I create another new list, 72 00:04:21,350 --> 00:04:23,330 and this time I'll just call it new list, 73 00:04:23,330 --> 00:04:27,490 and say that it's the concatenation of fruit and numlist, 74 00:04:27,490 --> 00:04:30,800 what you'll see is that we create a third list, 75 00:04:30,800 --> 00:04:37,685 and that third list contains some elements from fruit and some elements from numlist. 76 00:04:37,685 --> 00:04:41,780 So, we're not affecting either fruit or numlist in anyway. 77 00:04:41,780 --> 00:04:43,820 We're just creating a new list that actually 78 00:04:43,820 --> 00:04:47,195 has both of their elements concatenated together. 79 00:04:47,195 --> 00:04:50,975 If I create a fourth list of zeros, to say, 80 00:04:50,975 --> 00:04:52,490 zero repeated four times, 81 00:04:52,490 --> 00:04:56,975 then you can see that that's a fourth item in our global frame. 82 00:04:56,975 --> 00:05:01,505 So, let's answer some questions about concatenation and repetition. 83 00:05:01,505 --> 00:05:03,365 So, this question asks, 84 00:05:03,365 --> 00:05:05,555 what's printed by the following statements? 85 00:05:05,555 --> 00:05:08,315 So, we create a-list, a-list with three items, 86 00:05:08,315 --> 00:05:09,640 one, three and five, 87 00:05:09,640 --> 00:05:12,150 and b-list with another three items, two, 88 00:05:12,150 --> 00:05:16,995 four and six, and we print out the value of a-list plus b-list. 89 00:05:16,995 --> 00:05:19,800 What do we get? So, it can be tempting to say, one, two, 90 00:05:19,800 --> 00:05:20,910 three, four, five, six, 91 00:05:20,910 --> 00:05:22,830 because that's what's natural to us. 92 00:05:22,830 --> 00:05:26,515 But, because a-list is one, two, three, 93 00:05:26,515 --> 00:05:30,559 all of those items come before the items of b-list, 94 00:05:30,559 --> 00:05:32,360 which are two, four and six. 95 00:05:32,360 --> 00:05:36,995 So, the result that we get from a-list plus b-list is one, 96 00:05:36,995 --> 00:05:42,120 three, five, and then two, four, six. 97 00:05:42,120 --> 00:05:45,170 So, the order is the elements of a-list in order, 98 00:05:45,170 --> 00:05:47,495 and then the elements of b-list in order. 99 00:05:47,495 --> 00:05:54,660 So, that means that the answer is going to be C. Let's do another one. 100 00:05:54,680 --> 00:05:57,540 So, in this question, we create a list, 101 00:05:57,540 --> 00:06:00,410 a-list and set it to a list with three items one, 102 00:06:00,410 --> 00:06:05,495 three and five, and then we print out the value of that repeated three times. 103 00:06:05,495 --> 00:06:08,985 So, what we should get is this repeated three times. 104 00:06:08,985 --> 00:06:11,100 So, one, three, five, one, three, 105 00:06:11,100 --> 00:06:12,810 five, one, three, five, 106 00:06:12,810 --> 00:06:14,640 a list that has nine items. 107 00:06:14,640 --> 00:06:16,050 That's going to be answer 108 00:06:16,050 --> 00:06:21,760 C. That's all for concatenation and repetition. See you next time.