I am out of trial and error again Lists

Seymore4Head Seymore4Head at Hotmail.invalid
Fri Oct 24 19:48:16 EDT 2014


On Fri, 24 Oct 2014 16:27:58 -0700 (PDT), Rustom Mody
<rustompmody at gmail.com> wrote:

>On Saturday, October 25, 2014 4:30:47 AM UTC+5:30, Seymore4Head wrote:
>> On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:
>> 
>> name="123-xyz-abc" 
>> a=range(10)
>> b=list(range(10))
>> c=str(list(range(10)))
>> print ("a",(a))
>> print ("b",(b))
>> print ("c",(c))
>> 
>> for x in name:
>>     if x in a:
>>         print ("a",(x))      
>>     if x in b:
>>         print ("b",(x))  
>>     if x in c:
>>         print ("c",(x))
>> 
>> B is type list and C is type str.
>> I guess I am still a little too thick.  I would expect b and c to
>> work. 
>
>Lets simplify the problem a bit.
>Do all the following in interpreter window
>
>>>> name="012"
>>>> b=list(range(3))
>
>>>> for x in name:  print x
>
>>>> for x in b: print x
>
>Same or different?
>
>Now go back to Denis' nice example and put in type(x)
>into each print
>
>Same or different?

First.  The interpreter is not good for me to use even when I am using
Python 3 because I forget to add :  and I forget to put () around the
print statements.

To keep me from having to correct myself every time I use it, it is
just easier to make a short py file.

Here is mine:

name="012"
b=list(range(3))
for x in name:  print (x)
print (type (x))
for x in b: print (x)
print (type (b))

I don't understand what I was supposed to learn from that.  I know
that name will be a string so x will be a string.
I would still think if you compare a 1 from a string to a 1 from a
list, it should be the same.

Obviously I am wrong, but we knew that already.
I get they are not the same, but I still think they should be.

name="012"
b=list(range(3))
print (name[1])
print ([1])

1
[1]

OK  I get it.  They are not the same.  I was expecting "1"





More information about the Python-list mailing list