There is a mgic method in python called contains which should return true if item is in self, false otherwise.
The method signature of contains:
Samples:
BUT DONT USE this magic methods this way, as it should be used in internal class operations.
Membership test operator for this is
Side note: methods which are started by _ (underscore) should not be called directly outside of class scope. They meant for internal class operations.
#python #membership #in #contain #exist
The method signature of contains:
object.__contains__(self, item)
Samples:
>>> 'sample_output'.__contains__('sample')
True
>>> 'sample_output'.__contains__('ASL')
FalseBUT DONT USE this magic methods this way, as it should be used in internal class operations.
Membership test operator for this is
in. In case you want to test membership:>>> 'sample' in 'sample_output'
True
>>> 'ASL' in 'sample_output'
False
Side note: methods which are started by _ (underscore) should not be called directly outside of class scope. They meant for internal class operations.
#python #membership #in #contain #exist