Q:

What can the ADD/OR in python be used for?

I am curious about how to use  add and or in diverse way when I'm reading python2.7 document about data structure.
Below is its example code:
>>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance'
>>> non_null = string1 or string2 or string3
>>> non_null
'Trondheim'

and and or is called short-circuit operation.Their arguments are evaluated from left to right, and evaluation stops as soon as the outcome is determined. But it returns the last evaluated argument.What can I use it for?I can do it using for ... in, if and other construction because in my opinion, the return value maybe not what I want using add or or.

A:

In the context of the example you can use or to select the first non-empty string.
More broadly or will give you the first non-false, not-none, non-empty value.
Similarly and will give you the last of such elements.
I tend to use them most frequently with boolean values where they correspond to the logical operations of at least one oprand must be true (for or) and all oprands must be true (for and).

