python operator, no operator for “not in”

后端 未结 2 1525
长发绾君心
长发绾君心 2020-12-11 00:55

This is a possibly silly question, but looking at the mapping of operators to functions I noticed that there is no function to express the not in operator. At

2条回答
  •  北海茫月
    2020-12-11 01:15

    Another function is not necessary here. not in is the inverse of in, so you have the following mappings:

    obj in seq => contains(seq, obj)
    
    obj not in seq => not contains(seq, obj)
    

    You are right this is not consistent with is/is not, since identity tests should be symmetrical. This might be a design artifact.

提交回复
热议问题