A certainl part of an if() structure never gets executed.

Nick the Gr33k support at superhost.gr
Fri Jun 14 09:07:56 EDT 2013


On 14/6/2013 3:40 μμ, Jussi Piitulainen wrote:
> Nick the Gr33k writes:
>> On 14/6/2013 12:21 μμ, Jussi Piitulainen wrote:
>>> Nick the Gr33k writes:
>>>> On 14/6/2013 11:28 πμ, Jussi Piitulainen wrote:
>>>>
>>>>>>>> 'Parker' and 'May' and '2001'
>>>>> '2001'
>>>>
>>>> But why?
>>>>
>>>> that expression should return True since all stings are not empty.
>>>
>>> It returns a value that counts as true in a conditional statement or
>>> expression:
>>
>> When a look at ('Parker' and 'May' and '2001') i can't help it but
>> interpret it as:
>>
>> Return True if  'Parker' is not an empty string AND 'May' is not an
>> empty string AND'2001'  is not an empty string.
>
> Nah. That expression would be:
>
>    True if ('Parker' != '' and 'May' != '' and '2001' != '') else False
>
> The one at hand is more like: 'Parker' if 'Parker' does not count as
> true, else 'May' if 'May' does not count as true, else '2001' (which
> counts as true if it counts as true, else it counts as false ...).
>
>> i just don't understand why it returns back the last value instead.
>
> I suppose the value can be useful, and there is generally no harm in
> it. But why not adjust your expectations to the reality? You can still
> ask why.
>
> This behaviour of the /and/ and /or/ was used to simulate the
> conditional expression (_ if _ else _) before the latter was in the
> language.
>
>>>>>> '' and whatever
>>> ''
>>
>> Why does it return th first object back
>> isn't it like saying False and True and resulting in False?
>>
>> Please put it in else word how Python unerstand that.
>
> That would be: '' if '' counts as false, else whatever.
>
> And yes, when the first expression determines the value, the second
> expression is not evaluated. /or/ is similar.
>

Thanks for explaining this but i cannot follow its logic at all.
My mind is stuck trying to interpret it as an English sentence:

if ('Parker' and 'May' and '2001')

if ('Parker' or 'May' or '2001')

i just don't get it and i feel silly about it.

-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list