Membership Test | Development | Online Course With Appy Pie Academy

Membership test

Lesson Details:
September 17, 2020

Video Transcription: In this lecture I'm going to tell you about the membership test in a set so I'm giving the command using member shape test this video is brought to you by Appy Pie’s Academy, you might be remembering we have used this membership test in case of tuples also so it is going to do the same thing as it did in case of tuples it will find a particular element if it is present if it is present in the set it will return boolean value true otherwise it will return boolean value false so I have taken this set with the name all and using the set method I have defined the elements 12 22 23 etc then I have written print 34 in or now what does it mean it will look for a value called 34 in the set or if it is present if it is there it will return boolean value true otherwise it will return false so as you can see the output is true after executing this program we have seen this output to be true why because the value 34 is present in the set now I have I'm going to give deliberately I am going to give a value which is not present in the set so I will execute this program and we will expect an answer false yes the output is false why because 100 is not present under is not present in the in the in the in the set so that is why it has returned the boolean value false okay we can alternatively we can do one thing we can take a variable like suppose I have taken the variable with the name flag so what I am going to do is I'm going to write like 45 in all so it is a membership test it will look for 45 in the set all and as usual what it will do is it will return true if it is present you that is not present it will return false so I'm giving the comment output will be stored in variable flag and as you might have judged the value of sorry the datatype of flag is going to be boolean so here data type of flag will be boolean in fact in python we call it bull so in general terms we call it boolean the value is either false or true so now in this output it is going to be true why because 45 is present in the set right as you can see in the set 45 was present so that is why it has returned the value true and when it returned the value boolean value true it assigned it to the variable flag and subsequently I printed the value of the variable flag which was printed to be true.

loader
Course content