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 and nor or restrict value , type return false , true, rather return last evaluated argument. useful, e.g., if s string should replaced default value if empty, expression s or 'foo' yields desired value.

(emphasis mine)

note behavior isn't found not which, instead, returns true/false value based on argument provided.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -