Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Denis McMahon Newsgroups: comp.lang.python Subject: Re: I am out of trial and error again Lists Date: Fri, 24 Oct 2014 21:19:22 +0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: References: <2412654f-ac5e-4678-8956-afc4e27affb3@googlegroups.com> <3082ee74-3182-4ea5-9851-2b1326e5b34c@googlegroups.com> <9a1l4athfj10h7r3v69ddo95285n9cjlms@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 24 Oct 2014 21:19:22 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="23528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19TkHbcsj50p7oj4aU9vQ17yCDTP6nJbRA=" User-Agent: Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2) Cancel-Lock: sha1:pfk+408UDF59JtajzIcK6ZhSBRA= Xref: csiph.com comp.lang.python:79619 On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head wrote: > I do understand that. 7 is a number and "7" is a string. > What my question was...and still is...is why Python 3 fails when I try > using y=1 800 get charter > > y in range str(range(10)) > should work because y is a string and str(range(10)) should be "y" in > str(1) fails. > It doesn't give an error it's just not True when y is a number. This is because str(range(10)) does not do what you think it does. In python 2.x, str(range(10)) creates a string representation of the complete list, not a list of the string representation of the separate list elements. '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' In python 3.x, str(range(10)) creates a string representation of the list object. 'range(0, 10)' the only single digit strings in the python3 representation are "0" and "1" To recreate the python2 behaviour in python 3, use: str(list(range(10))) which gives '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' howver the test: if x.isdigit(): is much better. But finally, with your telephone number decoder, look at: http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py -- Denis McMahon, denismfmcmahon@gmail.com