 What's up guys? RudeLanel here and we're looking at even more Python code today We're continuing our little video series and tutorials and we've been looking at lists lately Now lists are those those data types that hold a lot of variables and a lot of values and a lot of information and They're they're awesome because you can index these sort of things and when you index them You retrieve that value that is at that that certain position that you indexed now when you do this you can actually Reset the current value you can look over this on the side notes We have an example the new list equals four ten twenty three and then we set new list zero Which would equal four and we change that to five so four in the new list becomes five and the new list eventually equals five ten and twenty three So hey, let's check this out and I don't see what we can do I am actually gonna open up a new program here with control n Let's save this as a filed up Python make this visible and then make it vanish boom And I'll get started with a shebang line Just to have good practice. So looks like I got a question mark there. That's kind of weird Alright now Let's get started. Actually, I'm gonna define a function because I think that's a good idea for the moment I'm gonna call it main because I like that word, you know, it's pretty it's got a it's got four letters All right, so hey, we got a new list here and our new list can equal. Let's say John Doug Actually, let's make this a multi-line thing just so we get into that that practice that idea new list can equal John let's say and then a Doug Tucker Brian and Tony And now that's okay to have that comment there even though we don't have a value afterwards because that's just the way it can go Now what I'm gonna do here is I'm gonna use a for loop We're going to use the for loop and go through this new list because we can use our in keyword of that membership operator We can see the elements that are actually in that list So let's go for item in new list and Let's loop and print out all the items that are inside new list. Let's print out item And let's actually concatenate on there Says hi And let's run this John says hi Doug says hi Tucker says hi Brian says hi Tony says hi now This is cool because item is being replaced with each value inside the new list And we can reset this though. We can actually change item to equal say poop face Because when I used to play Pokemon I named all my arch enemies poop face And now when we're done that we've got poop face says hi over and over and over again So I'm interested. What is the value of new list now? What is inside new list if we give it a go? It's still John dog Tucker and Brian and Tony because it's only item that's being manipulated not the actual things here but if we tried this in a different manner if we actually Indexed this with a while loop if we did count Equals zero limit Equals and I want to introduce a new function to you guys here called Len or Len and this will actually retrieve the length of any objects you pass to it you could send it in a string And actually let's print out Print the limit here So in our case this will run as six because we have One two three four five six six characters in here now We aren't counting this in the way that it normally would though because normally you'd use that first character as zero, right? If you were if you were taking in that program or lens But it's using that that human readable form because usually we would use this in loops If we do zero if we do counters less than limit it'll still increment six times But it goes from zero one two three four five So that's six when you include that zero So that's why it uses this six because it expects you to use the less than term But okay what we're trying to do here now is trying to try and find the length of new list Now when we print this out we have five because we have five elements here. We have John Doug Tucker, Brian and Tony. That's five people Okay, so now let's do a while loop indent this While counter is less than limits I'm going to remember to increment the counter because I don't want my computer to freeze like it did last time That was a little embarrassing and now we can print new limits new new list. I'm sorry and we can index with counter And we can catnate on here says hi Now when we when we run this we print this out It says John says hi Doug says hi Tucker says hi Brian says hi and this makes sense because we're using that number to Index each value inside new list Now if we remove this little piece here though remove the print limit because we don't really need that anymore What if we had done what we were doing before what if we changed? What is the equivalent of item in our loop, which is really new list counter What if we change that to poop face? New list item remember to remember to index this here. Don't set the entire list to a string that would be catastrophic Change it to poop face now. What it's doing is it's assigning each bit of the of the list to poop face So when we run this We get John says hi Doug says hi Tucker says hi Brian says hi because we're printing it before we do this when we switch it back though when we actually Print it out though. We have poop face poop face poop face poop a poof face. I can't even speak. It's a tongue twister And that's what happens though because we're using the indexing we've Actually changed every single element inside this new list and changed it to poop face because we've used our loop We've looked at it in the force when with the for loop We've looked at in the while loop and we've introduced some new topics and concepts here though But this actually wasn't the point of the video what I'm trying to show you here is that you can Assign things in the list While using that list But that isn't what we're getting at here what I want to show you is a new sort of data type this is called a tuple and a tuple is Only useful for retrieving the variables and the values that you save inside that data type It's a lot like a list and that it's holding multiple values But it's you can't add any you can add things to it, but you can't change the value So let's give it a go. Let's try what you do here The syntax is a same as if you were for a list I'm just gonna name the variable new tuple instead except using parentheses rather than those brackets So if we if we run this global name new list is not defined. Okay, we have to change it down here We run this new tuple We run this jug John dog Tucker Brian and Tony just the way we had it before But we can't modify any of these if we tried to do if we tried to run our little while loop here It'll freak out Actually only because we haven't changed it to new tuple first of all Tuple and then change this to new tuple as well It'll freak out because tuples are not allowed to assign things to the elements of the items that are inside Their you know their their scope But you can add things to it It's it's it's strange if you if you have a new tuple Let's let's kill these here print new tuple to begin with and then we had let's say another tuple Which can we can we can just add on there say What am I thinking what am I thinking do we have Kevin? We don't have Kevin Kevin and Chuck if we add If we use the new tuple and then our assignment operator plus equals Another tuple and then we print new tuple once again This is gonna work. This is gonna run perfectly fine because It allows you to add things to the tuple But it doesn't let you to change it doesn't allow you to change the values inside it If we look at if we just tried to do this very singularly new tuple Let's say zero So we're gonna change John in this case And say John to a girl just because that's funny And we'll run this except we'll get an error though because it's that that's an exact same problem Tuple does not the tuple objects do not support item assignment So you can't change the values that are inside their scope Except you can do that with lists So part of me Wonders what the point of tuples are I guess it could be a security thing Whether you just don't want to be able to change things inside your array if you're a program and you don't want that to happen But I don't know it's interesting to see when a programmer uses these tools and uses these ideas that they're able to use So that's all I've got for you today. I hope you were able to understand this one I know we covered a lot of ground while using item assignment. We used Four loops we use the while loop and everything But I don't think I've covered on these as much as in as in much detail as I should have So I hope you guys will be able to understand this especially this the for loop here because that's sort of a crucial thing to know You can use the for loop to loop through items by using that in operator The in membership operator every item that is inside the list can be accessible By looping in with that and you can change sort of things like that But thank you for watching guys. Thank you so much It's really great that I have such a such a nice audience and I'm hoping these things are working for you guys under Understanding your learning new things and you can start to do some of your own things in Python But uh, yeah, it'd be awesome if you could give me a like maybe a comment maybe subscribe I don't know. It's it's whatever you want to do. I'd be really awesome If you could check me out at my website no shell calm, but hey, I'll stop self advertising here. I'll see you again. Goodbye