I am out of trial and error again Lists
ian.g.kelly at gmail.com
Fri Oct 24 23:11:14 CEST 2014
On Fri, Oct 24, 2014 at 2:58 PM, Seymore4Head
<Seymore4Head at hotmail.invalid> wrote:
> 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.
More information about the Python-list