I am new in Python. I am using Python v2.7.
I have defined a simple class Product:
class Product: def __init__(self, price, height, width): self.price = price self.height = height self.width = width Then, I created a list, which is then appended with a Product object:
# empty list prod_list = [] # append a product to the list, all properties have value 3 prod1 = Product(3,3,3) prod_list.append(prod1) Then, I created another Product object which is set the same initialize values (all 3):
prod2 = Product(3,3,3) Then, I want to check if prod_list doesn't contain a Product object that has price=3, width=3 & height=3, by:
if prod2 not in prod_list: print("no product in list has price=3, width=3 & height=3") I expect there is no print out message, but it is printed out. In Python, how can I check if a list doesn't have an object with certain property values then?