Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed1.swip.net!newsfeed3.funet.fi!newsfeeds.funet.fi!news.helsinki.fi!.POSTED!not-for-mail From: Jussi Piitulainen Newsgroups: comp.lang.python Subject: Re: A certainl part of an if() structure never gets executed. Date: 14 Jun 2013 21:17:13 +0300 Organization: University of Helsinki Lines: 31 Sender: jpiitula@ruuvi.it.helsinki.fi Message-ID: References: <2bc90d3b-09c2-4315-9357-ff7f039465e0@googlegroups.com> <51b926a3$0$29997$c3e8da3$5496439d@news.astraweb.com> <51ba6e92$0$29997$c3e8da3$5496439d@news.astraweb.com> <51bb454c$0$29997$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: ruuvi.it.helsinki.fi Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: oravannahka.helsinki.fi 1371233833 3341 128.214.205.65 (14 Jun 2013 18:17:13 GMT) X-Complaints-To: usenet@oravannahka.helsinki.fi NNTP-Posting-Date: Fri, 14 Jun 2013 18:17:13 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: csiph.com comp.lang.python:48201 Nick the Gr33k writes: > >>> (a or b or c) > 'abcd' > > This for me, should evaluate to True but instead it has been > evaluated to the first variable's value, which is a truthy value of > course since its not an empty string, but shouldn't it return True > instead? In your own programs, write bool(a or b or c) instead. And instead of writing (k in (a or b or c)), write ((k in a) or (k in b) or (k in c)) -- you can use fewer parentheses if you like, but only if you are comfortable with it. (Here, I use the outer parentheses to separate Python from English. I might not use them in code.) Usually such expressions occur as conditions in conditional statements or conditional expressions. There, the bool() makes no observable difference. > Returning True is the same thing as returning a variable's truthy > value? I think that's a good approximation. Strictly speaking, True is a particular value in Python, but I think that at the moment you need to understand that what is important is how the value is interpreted as a condition in a conditional statement (if condition:, elif: condition), a conditional expression (x if condition else y), a while loop (while condition:). >>> while "ijkl": print("it doesn't matter")