 Hello everyone in this video. I'm going to introduce to you some new terms that we're going to be using throughout the semester or one new term which is Abstract data type. Okay, so you've already encountered data types and we've started talking about data structures But these three things kind of live together in harmony, and I want to make sure that we Kind of orient our brains around what these different things are because it's again It's going to be terms we use over and over But before we get into that The good news is we're basically done with new Python stuff, right? Like classes and objects That's like the last big Python thing you're going to learn As long as you've used dictionaries if you've not used dictionaries we'll come into them But there's nothing else really that's new However, there are probably some concepts that you've encountered before That are going to be really important for you to now understand whereas maybe before we glossed over them One of them is the concept of none in Python. Okay So I got some code here grab this code copy and paste it into an editor And I'm going to switch over there and talk about it. Let's see right here Let's get this big on the screen for you. There we go All right, so this is the code from the slide. All right, this is just demonstration code now What does this code do? Okay? I've got a function up here that takes an item and a list and It starts at the beginning of the list and it says if item equals X Return the index. Okay? otherwise increase the index by one and Keep going. Okay, so this is saying all right. Tell me where in this list that an item exists So for example 120984 exists that index zero one two three So that's what I expect to see here, right? But now when I call get index 9999 this thing isn't here Well trace that through the code. What's gonna happen? Okay? Well, what's gonna happen? Well, let's run it first of all First I get three Right because this item is at index three zero one two three and then I get none Okay, printing. I'm printing at oh and none capital N. Very important Why did I get none? Right? You'll notice up here This function. It's only return statement is right here, right? If I find the item in the list return something Otherwise keep going keep looping. Well, when does this loop end? It ends when I've inspected everything in the list and once I've inspected everything in the list But I haven't found it What does this code do? Well from our tracing exercise the loop will Will come to this and it'll say I don't have anything more in a list Jump over to the end of the loop, which is basically down here But there's nothing there. So what happens? Well, Python says, oh, I've reached the end of the function Let me just get out of it. Let me return Well, Python does in fact return something Right here if you don't return out of a function Python will automatically return none for you Okay, this happens for every function So I don't even have to write it Python just does it So that's why I'm getting none here. Okay, none is a really important Concept though. Okay, you've probably run into other errors like things like if I try and add Let's say I get the index here Which I know is gonna be none But let's say I want the item before the index So let me do like print index minus one you've probably run into an error that looks something like this Unsupported operands for none type, right? It's mad because this value is none Because 9 9 9 9 isn't in the list and it just returns none by default when it exits the function None minus one Doesn't mean anything to Python. That's what it's saying. Okay So when you see this none type in an error message, that's what they're talking about I mean something you're working with is actually giving you this very special value called none. Okay, you need to Be kind of familiar with what none is think of it like true and false right true True has a special meaning false has a special meaning none also has a special meaning. It means no value It's a value that means no value. There's nothing there if you come from Java land or C++ land This is null in those languages. Okay So none is a building constant and it's used to represent absence of value again. Think of it like a true false and then none right You can use it as a value like you can check to see if a variable points to none if nothing comes back Actually, let me show you that Get back to my code, right? So the second function returns none, right? you can use none in like conditional checks if Get index is None, this is the way we check for these special values if get index is none You should also get in the habit of using is true or is false. This only applies to true false and none Okay, you would not be wrong to do Equal equal none. That's okay, too, right? But pie charms gonna warn you that's not what you should do You should do is but you only use is for true false and none That's it. You don't do equally if you're comparing numbers. You don't do it if getting index is none print Couldn't find the thing else print It's there Couldn't find the thing, right? So this is returning the value none and then you can do a comparison with it Okay, you can compare to none Equal equal works. It's just not quite dogmatically correct. All right, so By default Python functions and methods return none if you do not specify a return value Okay, so we are gonna leverage that in future assignments, but just start wrapping your head around now what none means Okay, let's go back We're talking about this lecture is about abstract data types data types and data structures We talked we've been talking about how the Python list data type is Implemented with an array list data structure So the list the data type is a class in Python and the data Structure is how that class kind of arranges its information. Okay You don't have any control over how Python's list works But we are gonna write our own data types our own classes that do control How the data is arranged internally and that'll give us some benefits and some drawbacks Okay, so let's introduce the concept of an abstract data type or ADT ADTs are conceptual things. They are all Cross-computing across all languages and computing if you walk up to a programmer and you say For example one ADT is a stack. We'll talk about stacks next if you walk up to a programmer Who's only ever written code in C++ and Java. They'll say I know what a stack is You will say I know what a stack is and you'll have learned it in Python These are things that transcend languages. They're part of computing and usually they solve around a particular problem Different ADTs do different things well And ADT has a collection of data its state, right? These are abstract terms and Behavior, which are its operations things that manipulate the data. Okay. All right, so what does that sounds a lot? Like our definition of a data type that we've had before and it is one's abstract. It's a concept It's up in the clouds somebody thought of it The data type thing that distinguishes an abstract data type from a concrete data type or just data type or type or class Is that a data type is an implementation of an ADT in a language? So Python has a list data type Java has a list data type C++ has a list data type and they are different But they all kind of behave similarly Okay, the data structure now is how inside the data type the information is organized That's what we really will care about throughout the remainder of this course How are we organizing the data to solve problems? But this is the lingo. This is the structure the lowest level Inside the memory. How do we organize the data? That's the data structure next level up The concrete class that we use to solve a problem. That's a data type Finally the highest level the abstract data type just What is this thing that solves problems and what can it do? Okay, so you have been working with an abstract data type and ADT But we didn't call it that Your very first one is what we call the unordered list ADT An unordered list in computing not just in Python and computing is a collection of items where each item Holds a relative position with respect to the others This is what Python's list type implements. Okay This is the abstract data type. You can find it also in Java and in other languages Okay, but it's just a collection of items. That's a useful thing to have in computing a collection of items where each one is In a relative position to another. Okay, that's neat. It's a list. That's a Very useful very basic kind of abstract data type. It's an unordered list Because the position of the items in the list is not determined by the value the list isn't sorted it anyway The positions of the items depend on how you you added them into the list. Did you append them? Did you insert them? What did you do? But they're not sorted, right? They're not ordered in any way so an Unordered list right what can you do with an unordered list abstract data type in any language an unordered list Should be able to add and remove items by value append items to the end Insert and remove at a specific index Tell you how big it is or if it's empty and you should be able to search an unordered list Again, these are general concepts of what you can do with a list, right? And you could do this with a list that you had on a sheet of paper Yeah, remove the fifth item in the list search for see if Bob is on my sheet of paper. These are abstract concepts now Python lists that Data type takes these concepts and and actually writes code to do it, right? you are going to and Next week make your own unordered list. You're gonna make a list that behaves almost exact that does Exactly what a Python list does But it works very differently You're gonna write the code for it and what we're gonna find out is a It's hard to do but be your list is gonna be way better than Python's list for certain very specific things And then Python's list is gonna be way better than your list for other specific things, okay? All right on ordered list is the ADT general things you can do with a list Python's list data type Concrete implementation of the unordered list in Python and then finally the array-based list There's really nitty-gritty details of how things are stored in continuous blocks of memory and how the arithmetic works for looking up items by index That's the data Structure, okay, so we are going to talk in the rest of the videos for this week about other ADTs That build upon the array list data structure and we're gonna create these ADTs and in your homework you're gonna use them to solve different problems, okay? So these three ADTs we're gonna talk about are the stack the queue and the deck and they use a List data structure internally but on the surface at a higher level they behave differently, okay? so These are basically structures where you can keep a collection of items, but the order of them is Matters and where things are kept matters, okay, so We are gonna talk about each one of these in turn in the coming videos