and operator on Python lists -
i've found strange behavior in python. 1 of students made kind of mistake trying find elements belong 2 lists, wrote:
list1 , list2 the strange behavior no error fired python 3! list1 , list2 has got value list2.
is there known reason this?
and evaluates truthness of 2 values provided.  if first true (see bool(list1)) second evaluated , returned. if first argument false (e.g [] , list2) value returned immediately.
in documentation on boolean operations rationale behavior stated clearly:
note neither
andnororrestrict value , type returnfalse,true, rather return last evaluated argument. useful, e.g., ifsstring should replaced default value if empty, expressions or 'foo'yields desired value.
(emphasis mine)
note behavior isn't found not which, instead, returns true/false value based on argument provided.
Comments
Post a Comment