Python Series- is Vs == Indepth Explanation- Boolean Evaluation
Hello all my name is krishnan welcome to my youtube channel so guys today in this particular video we are going to see the difference between is keyword and double equal to so here we are basically going to see two things one is is versus double equal to now remember there's a lot of confusion with uh people also and yesterday also i was taking one of the session where people had a lot of doubts with respect to ease and double equal to so let's try to understand this and let's try to take some of the examples so first of all i am going to make a list where i have elements like probably crash uh i have three names suppose so i say krish and then i say crush one right if i say krish to so i have these all elements right and similarly what i do this is my list one okay and then i'm just going to copy this entirely and then i'm going to basically paste it over here now when i have this and let me just rename this into list2 now in this video now what i will be doing is that now see this if i use list one double equal to list two right this is a simple code over here where i'm just writing list one is equal to list two this is nothing but double equal to basically means that we are going to compare whether these two lists are equal or not just understand this equal with the with respect to the elements that are present inside this if i try to execute this definitely it will be coming as true okay so here i'm actually checking whether list one and list two are equal or not and obviously just by seeing it all the elements inside this list are different if i try to change this into something else and if i try to again execute it it is basically giving me false so let me make it back okay now this is with respect to double equal to operation that basically means whatever things i'm actually trying to compare you know like if i'm if i made a string like crash and probably my b string is again crash okay that basically means that if i try to compare any of this kind of variables which is having probably the same value inside it but remember all this will be having a different different memory location so when i'm doing this kind of comparison a double equal to b i'll definitely be getting as true before going ahead with respect to this particular video this video has been sponsored by an academy so guys if you are in the final year of a graduation or planning to prepare for gate or eac examination then you are at the right place an academy is back with its cs or it batch evolve 2022 these batches are starting from 18 jan 2021 don't miss a single class take all the live session and prepare with the best unacademy educators including ravindra babu rahula if you don't know about ravindra babu ravula guys he's an amazing teacher and you can also see his youtube videos with respect to gate you will be getting 800 plus hours of total lectures covering the full gate or esc course along with solving all your doubts do make sure that you try to use my code that is kn06 to get an additional 10 percent discount you can also take the demo class to get a full clarity about the educator that is ravindra babu ravula and subscribe to this particular platform all the information regarding this will be given in the description of this particular video now coming to the is keyword okay so let's see if i try to use the same list1 and list2 and i'll try to use the is keyword so if i use list 1 is list 2 if i try to execute over here you can see that i'm getting false now why probably i'm getting a false will try to understand but before that let me take one more example over here okay now instead of just writing like this i'll just copy this and now i will just paste it over here and let me do one thing instead of assigning this particular value again remember whenever we are assigning some values over here this will be taking a different memory location it will get saved over here this will be stored in different memory location now instead of doing this i'll remove this and i'll assign it to list one now when i am doing this now just see what will be the output over here list1 is list2 so when i execute this this will be true okay i'll tell you why it is true let me just reverse this thing again instead of making list 1 let me write it at list2 is list1 okay now here also you can see this is true now remember one thing guys whenever we are using the east keyword okay is keyword is just not about comparison of the elements instead it will try to see first of all in list one we have saved some kind of elements over here you can see some of the elements items are there and this items probably may be like allocated in a different memory location in some memory location and that same reference is basically provided to the list too when we do like this and at that time when we try to compare with respect to the east keyword then it basically gives me a true value again understand guys here different objects are not getting created only one object has been created in the memory and that is being referred by both the variables that is the most important thing to understand with respect to double equal to this does not happen like that in double equal to you'll be having two different memory location and you'll try to compare whatever values basically stored within them and then it will try to say whether it is true or false and this is very very important because probably in the next video i'll be also uploading about numpy dot array versus numpy dot azure so tell me the difference between this anyhow i'll be trying to create a video in my next next uh video in python series but just understand what is the basic difference between np dot array versus np dot as array let me talk one more concept which is called as mutability now guys remember if i make this changes like this and if i assign list one to list two now suppose my list two of zero is basically krish if i try to change it to something like krish two suppose okay now if i go and see my list two and here you'll be able to see krishna krishna and krishna okay but what about list one well whether the list one will also get updated then we can definitely see over here the list one is also getting updated with respect to the elements so wherever mutability is possible see in this particular case something is stored in one memory location two variables are referring that if one variable a child should change that particular value it will also get reflected to the other things so that is the reason why we use shallow copy and deep copy i'll also be creating a video on shallow copy and deep copy and we'll try to see how we can prevent that in order to just prevent it what we have to do is that when we are assigning like this we just have to use dot copy operation to make it as a deep copy deep copy basically means it will create a different memory location even for list2 so i hope you understood this particular video this is the basic difference between is versus double equal to uh now you probably you may have understood when should we use double equal to and when we have to use is when does it give true or when does it get false right this is just like a boolean operation so this is all about this particular video guys i'll see you all in the next video have a great day thank you and all bye.