If Statement Error (Tic Tac Toe)

Mike Meyer mwm at mired.org
Tue Nov 1 17:39:08 EST 2005


ale.of.ginger at gmail.com writes:

> Thank you.  It seems I didn't understand logic statements as much as I
> thought I did!
>
> The one remaining question I have deals with this:
>
> if gameboard[cell] not in 'OX':
>         gameboard[cell] = 'O'
>      else:
>         print "This cell is already filled."
>         turnnumber -= 1
>
> (gameboard[cell] not in 'OX' is the gameboard[cell] != 'OX' text I sort
> of used in my code, right?)
>
> I am confused about "OX":  what exactly *is* it?  After that, I plan to
> rewrite all the code... :)

"OX" is a string. Saying "shortstring in longstring" is one way of
asking if shortstring is contained in longstring. In your case,
shortstring is one character long, but that's a string to
Python. Python doesn't have a distinct character data type.

While I'm at it, don't be confused by single quotes vs. double
quotes. Unlike other languages, in Python they have the same
meaning. The only difference is what you have to do to get a single
(double) quote in the string.

         <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list