1 00:00:01,110 --> 00:00:05,550 Hello and welcome to this utopia on python. 2 00:00:05,670 --> 00:00:12,320 This Python lists and ordered sequins all elements. 3 00:00:12,690 --> 00:00:18,500 And the list can contain a neat assortment of objects 4 00:00:21,080 --> 00:00:21,680 undone. 5 00:00:21,680 --> 00:00:31,870 Now we have discussed about data types such as indigenous clothes strings. 6 00:00:31,910 --> 00:00:41,420 In this example here we have a variable e that refers to a memory location and this memory location 7 00:00:41,900 --> 00:00:53,360 contains the value five the variable B refers to a memory location that contains the floating value. 8 00:00:53,380 --> 00:01:03,290 Sixteen dot o the variability refers to a memory location that contains the string Python three dot 9 00:01:03,300 --> 00:01:14,870 six coming to loose a list is an ordered sequence of objects and it can contain any arbitrary objects 10 00:01:15,740 --> 00:01:30,280 such as integers loading by numbers and strings and each of the elements in a list are also called items 11 00:01:30,670 --> 00:01:40,480 the items are separated by commas and finally the items are enclosed in square brackets and this is 12 00:01:40,480 --> 00:01:42,860 known as the list. 13 00:01:42,940 --> 00:01:44,740 So this list. 14 00:01:46,220 --> 00:01:53,050 Be named as list one and a list is not merely a collection of objects. 15 00:01:53,300 --> 00:01:57,710 It is an ordered collection of objects. 16 00:01:57,710 --> 00:02:01,970 That means these are added in which we specify the elements. 17 00:02:02,080 --> 00:02:10,370 When we define a list is the special characteristic of that particular list and this order is maintained 18 00:02:10,460 --> 00:02:14,510 as long as the list is in the memory 19 00:02:17,430 --> 00:02:18,740 say for example. 20 00:02:19,050 --> 00:02:24,210 I change the order of the first two elements. 21 00:02:24,210 --> 00:02:27,410 So here I have the floating point number. 22 00:02:27,780 --> 00:02:32,690 And then an integer and then we have this string. 23 00:02:32,730 --> 00:02:42,570 So in this case these two different lists even though the elements in both the list are the same. 24 00:02:42,570 --> 00:02:47,000 So let's check this in the Jupiter note book. 25 00:02:47,040 --> 00:02:49,950 So here I have my list. 26 00:02:49,950 --> 00:02:54,360 The list is one which has three items. 27 00:02:54,460 --> 00:02:59,040 Five the integer 5 and then the floating point number sixteen dot org. 28 00:02:59,070 --> 00:03:02,560 And then a string by then three dot six. 29 00:03:02,560 --> 00:03:09,560 Now if I want to know the memory location of the memory address to which this list is pointing to. 30 00:03:09,570 --> 00:03:17,040 We use d i d function just as we used for those drawings and then integers. 31 00:03:17,310 --> 00:03:23,100 So ideal in is the one. 32 00:03:23,180 --> 00:03:26,300 So this is the memory location. 33 00:03:28,340 --> 00:03:33,470 To which the variable LSD one is pointing to. 34 00:03:33,580 --> 00:03:45,690 Now I'm going to change the positions of the first two items in the list so sixteen dot org is the first 35 00:03:45,690 --> 00:03:54,680 element and then we have the integer and then the string by then three dot six. 36 00:03:54,680 --> 00:04:02,170 So let's execute this set and then check the memory location. 37 00:04:02,540 --> 00:04:11,420 So you can see once we have changed the the position of the elements the memory location has changed 38 00:04:11,790 --> 00:04:20,900 so which means which means the order in which we specify the elements when we define a list is is the 39 00:04:21,080 --> 00:04:23,960 characteristic of that particular list 40 00:04:27,130 --> 00:04:32,020 let us now see how lists are stored in the memory. 41 00:04:32,110 --> 00:04:42,340 So in our example that we have just considered we have defined debated in E which refers to the memory 42 00:04:42,340 --> 00:04:43,110 address. 43 00:04:43,210 --> 00:04:50,970 This is the memory address and this memory address contains divide to find Nick. 44 00:04:51,140 --> 00:04:58,300 We then defined the relative in B which refers to the memory address. 45 00:04:59,150 --> 00:05:06,980 And this particular memory address contains devalue sixteen dot o which is a floating point number and 46 00:05:06,980 --> 00:05:18,590 then we have defined the word in C which refers to the memory address your and this memory address contains 47 00:05:18,620 --> 00:05:22,670 devalue Python three dots six. 48 00:05:22,700 --> 00:05:27,490 Now we have defined a list later. 49 00:05:28,590 --> 00:05:40,610 Which refers to the memory address your and this memory location contained the address of each of the 50 00:05:40,610 --> 00:05:42,160 elements in the list. 51 00:05:42,200 --> 00:05:52,640 Say for example the first element in the list is the value five and the value five is contained in this 52 00:05:52,850 --> 00:05:54,410 memory location. 53 00:05:55,520 --> 00:06:06,560 So the memory location to which the list is binding to contains the address of the first element in 54 00:06:06,560 --> 00:06:08,240 the list next. 55 00:06:08,540 --> 00:06:16,630 The value sixteen dot or is contained in this memory location here. 56 00:06:16,780 --> 00:06:17,310 So 57 00:06:20,550 --> 00:06:24,210 here we have the address of the Element sixteen Dot. 58 00:06:24,240 --> 00:06:26,030 Or next. 59 00:06:26,130 --> 00:06:28,350 The third element is the string 60 00:06:31,000 --> 00:06:33,570 but just contained in this memory location. 61 00:06:33,670 --> 00:06:45,940 So yeah we have the address the string and finally as we know this memory location contains the value 62 00:06:45,950 --> 00:06:56,630 five this one here contains the brand new sixteen dot or and this contains the string. 63 00:06:56,700 --> 00:07:03,110 So this is how lists and other data types are stored in memory. 64 00:07:03,330 --> 00:07:11,510 A list can contain any number of objects from zero to as many as your computer's memory of the number 65 00:07:13,200 --> 00:07:15,810 and list objects need not be. 66 00:07:15,810 --> 00:07:24,530 You'll need a given object again appeared in a list multiple times next list. 67 00:07:24,830 --> 00:07:36,090 Mutable once a list has been created the elements can be added deleted shifted and moved around at will. 68 00:07:36,750 --> 00:07:45,770 And by then belied a wide range of ways to modify this until now we have discussed about data types 69 00:07:45,770 --> 00:07:56,120 such as integers loads and then strings and all of these data types are immutable but less mutable and 70 00:07:56,450 --> 00:08:04,190 that add methods which can be applied on this which we will talk about and did in the later sections. 71 00:08:04,190 --> 00:08:06,490 For now we will come to. 72 00:08:06,830 --> 00:08:17,550 One method called the append method which append element to the end of the list so here we have a list 73 00:08:18,120 --> 00:08:26,040 enlistees one that has the element five sixteen dawdle and python 3.0 6. 74 00:08:26,070 --> 00:08:38,760 Now I have applied the method append on the list a list you run using D dot operator and I have POS 75 00:08:38,760 --> 00:08:40,710 D argument code. 76 00:08:40,860 --> 00:08:53,310 Now after this method is applied on the list the list will now be changed to include the element at 77 00:08:53,310 --> 00:09:05,490 the end of the list then we assign say Bill X the value 10 that means X refers to a memory address that 78 00:09:05,490 --> 00:09:09,980 contains derived Newton now. 79 00:09:10,210 --> 00:09:16,460 Later I will change the value X from 10 to 7. 80 00:09:16,570 --> 00:09:26,230 In this case what does already dead in the memory address is not changed but now x refers to a new memory 81 00:09:26,230 --> 00:09:30,320 address which contains divide 7. 82 00:09:30,340 --> 00:09:33,670 That means integers. 83 00:09:33,730 --> 00:09:34,770 Immutable. 84 00:09:34,890 --> 00:09:43,500 We cannot change any value that is on duty did in a particular memory Atlas coming to this. 85 00:09:43,570 --> 00:09:50,690 This is the list that are defined a list D1 then which contains these three elements. 86 00:09:50,700 --> 00:09:54,150 Five sixteen or and item three point six. 87 00:09:54,170 --> 00:10:04,390 Now I have applied the append method on the list listing one after this has been applied. 88 00:10:04,580 --> 00:10:14,350 The first position we have the integer 5 and then we have a floating by number and then as during and 89 00:10:14,350 --> 00:10:20,080 after that the value horde has been appended to the list. 90 00:10:20,080 --> 00:10:28,240 The data in the memory and address has been changed in case of Miss because lists are mutable. 91 00:10:28,240 --> 00:10:36,390 So let us check the memory location before and after applying the append method on the list. 92 00:10:37,300 --> 00:10:47,500 So here I have the list in one containing these three elements and Raven now call the the idea function 93 00:10:47,950 --> 00:10:59,480 on the list listing one so this is D memory location to which a list to one is adapting to now let us 94 00:10:59,570 --> 00:11:16,160 apply the append her no bias the argument for executed the same then we will display the missed it let's 95 00:11:16,160 --> 00:11:19,330 do one so devalue. 96 00:11:19,340 --> 00:11:31,510 Ford has been added to the end of the list and we will now check the memory atlas of the list a list. 97 00:11:31,510 --> 00:11:43,690 One so as you can see here the memory address has not been changed but the data in the memory location 98 00:11:43,960 --> 00:11:45,400 has been changed. 99 00:11:45,430 --> 00:11:54,280 That is the value Ford has been added to the end of the list within the same memory address next element 100 00:11:54,310 --> 00:12:03,040 in a list can be accessed individually using indexing and the individual elements in a list can be accessed 101 00:12:03,070 --> 00:12:05,720 using an index in square brackets. 102 00:12:05,800 --> 00:12:14,310 Say for example if we want to access the first element in the list the list u 1. 103 00:12:14,490 --> 00:12:17,660 This is how we treat the element. 104 00:12:17,680 --> 00:12:21,260 We place the index within square brackets. 105 00:12:21,300 --> 00:12:26,740 This is similar to what we have done for strings next. 106 00:12:26,960 --> 00:12:31,050 List indexing is zero based as it is with strings. 107 00:12:31,250 --> 00:12:35,470 So the first element are the item in the list. 108 00:12:36,530 --> 00:12:45,990 It is given an index Z or the next element has an index 1 to 3 and then so on 109 00:12:49,460 --> 00:12:57,260 Biden allows negative indexing product sequences sequences such as strings and lists. 110 00:12:57,330 --> 00:13:09,370 So LSD 1 0 minus 1 retrieves the last item in the list and trying to access an element. 111 00:13:09,440 --> 00:13:12,110 Other than this will raise an index. 112 00:13:12,150 --> 00:13:19,960 Edit the index must be an integer and we can't use a float or any other data type. 113 00:13:20,000 --> 00:13:23,620 This will result in a type error. 114 00:13:23,660 --> 00:13:35,530 So for example if we give the index as then this will throw an error because no element in the list 115 00:13:35,620 --> 00:13:37,840 with the index 10.