Python if not == vs if !=

后端 未结 7 1399
轻奢々
轻奢々 2020-12-07 08:09

What is the difference between these two lines of code:

if not x == \'val\':

and

if x != \'val\':

Is one

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 08:38

    It's about your way of reading it. not operator is dynamic, that's why you are able to apply it in

    if not x == 'val':
    

    But != could be read in a better context as an operator which does the opposite of what == does.

提交回复
热议问题