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

Jussi Piitulainen jpiitula at ling.helsinki.fi
Fri Jun 14 04:28:17 EDT 2013


Nick the Gr33k writes:

>  >>> name="abcd"
>  >>> month="efgh"
>  >>> year="ijkl"
> 
>  >>> print(name or month or year)
> abcd
> 
> Can understand that, it takes the first string out of the 3 strings
> that has a truthy value.
> 
>  >>> print("k" in (name and month and year))
> True
> 
> No clue. since the expression in parenthesis returns 'abcd' how can
> 'k' contained within 'abcd' ?

Why shouldn't (name or month or year) be different from (name and
month and year)?

Incidentally, you get better information without the print():

>>> 'Parker' and 'May' and '2001'
'2001'
>>> 

>>> 'Parker' and 'May' and 2001
2001
>>> 

Either way, the interactive prompt is your friend.



More information about the Python-list mailing list