Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:error': 0.03; 'string': 0.09; 'expectation': 0.09; 'false.': 0.09; 'assume': 0.14; '*you*': 0.16; '24,': 0.16; 'expect,': 0.16; 'throw': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'print': 0.22; 'error': 0.23; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; "doesn't": 0.30; 'characters': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'apparently': 0.31; 'prints': 0.31; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'clear': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'name:': 0.61; "you're": 0.61; 'first': 0.61; 'name': 0.63; 'happen': 0.63; 'skip:n 10': 0.64; 'subject:Lists': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=HytvaUNUMCNLGPH7JScg47nZI2vb+5Hz8OK+yVEHQI0=; b=wJoHCrSqsV45uS5A9oMFEoq/rmHG2O3gEwfFM4Ucj3XX7sDIk7RzPW3yYPaTd3YPt1 ZiECANGhUn70SpVwTCk+cTeh6C1aAjU8evY6xy9YudTNgNNj2PWL4oyzgkGLHxIE5C81 Pa+maqnYiCvJPo1+BxJoXH+2U92a6QVlqmrOSmr8f2OUSNjbb1bW/ycAaP9EvxSlEAAa 6I9azlz6HzrJdGglfPwTBsh4Y/NJEAuCNZRP4Xk7SBZtBmHf41FgqSxSrgflp0PIz+GG iUi3lB/FKnuVFuml70hPqDKxTU7yKdi7E/XgfpXsxlVFVjHNgUpkpfw8uLGFS/gyuT9M 3yLg== X-Received: by 10.70.133.200 with SMTP id pe8mr7014361pdb.123.1414185115720; Fri, 24 Oct 2014 14:11:55 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <2412654f-ac5e-4678-8956-afc4e27affb3@googlegroups.com> From: Ian Kelly Date: Fri, 24 Oct 2014 15:11:14 -0600 Subject: Re: I am out of trial and error again Lists To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414185119 news.xs4all.nl 2860 [2001:888:2000:d::a6]:47725 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79618 On Fri, Oct 24, 2014 at 2:58 PM, Seymore4Head wrote: > name="123-xyz-abc" > for x in name: > if x in range(10): > print ("Range",(x)) > if x in str(range(10)): > print ("String range",(x)) > > It doesn't throw an error but it doesn't print what you would expect. That prints exactly what I expect it to. The first if prints nothing, because you're testing whether a string is contained in a sequence of ints. That will always be false. The second if prints those characters from name that happen to be in the string "range(10)". That's the "1" and the "a". Apparently it doesn't print what *you* expect, which is why you need to make your expectation clear and not assume that we will just read your mind and immediately understand what you expect the code to do.