[Tutor] membership

john public apython101@yahoo.com
Tue, 4 Dec 2001 16:52:49 -0800 (PST)


t1 = "a little red moon"
t2 = t1
t3 = "redmond washington"

if ("r" in t2):
    print "t2"
    print t2

 this short piece of code works using the membership
function. However adding what is below:

t1 = "a little red moon"
t2 = t1
t3 = "redmond washington"

if ("r" in t2):
    print "t2"
    print t2
   
if ("re" in t2):
   print "t2"
   print  t2
if ("re" in t3):
   print "t3"
   print  t3


results in this error message:


t2
a little red moon
Traceback (most recent call last):
  File "C:\Python21\Tools\idle\amembership.py", line
10, in ?
    if ("re" in t2):
TypeError: 'in <string>' requires character as left
operand

Can someone tell me why this happens? I am a beginning
programmer. I started in C++ three weeks ago. I
switched to python two weeks ago when I realized it
was user friendly. My first program was a tic tac toe
game. I am now trying to write a program that stores
notes in lists,tuples or strings. The information is
written word. Such as "little red moon"
"redmond washington", "cute redhead I met at the bar".
I want to be able to search the lists, tuple's or
strings succesively for the letter "r", which would
bring up all three notes. Then "re" which would bring
up all three. Then "red" which would still bring up
all three. Then redm, which would bring up only the
list [redmond washington], and redh which would bring
up only the list [cute redhead I met at the bar]. Is
the membership function what I should be using to do
this? I am only a begginer and most of what is said on
this thread is way over my head. I seem to be able to
read and understand code directly better than read and
understand what is said about code. Once I can see
code I can run it. Then make substitutions and
changes. So far this seems to be the best way for me
to learn from others. I will be posting the tic tac
toe program after this. Thanks for all the help
everbawdy!

 John Public ( really my real name ;)really!




__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com