February 24th, 2004, 06:46 PM
quick question about "in"
when you say for example
for letter in txt:
if this in that
"in" signifies membership... how can i saw if something is NOT in something else
if this (is not) in that:
February 24th, 2004, 06:51 PM
just use "not in". For example:
both case will print out "IN".
if 1 not in [1,2,4]: print "IN"
if 1 in [1,2,4]: print "IN"
Help me, help you, help others...
February 24th, 2004, 07:04 PM
February 25th, 2004, 04:01 AM
using "in" with strings
incidentally, from Python 2.3 "in" (and "not in") can be used to test for substrings within a string, not just for single characters. For example:
>>> 'hell' in 'hello world'
>>> 'heaven' not in 'hello world'
Dave - The Developers' Coach
October 1st, 2005, 07:15 AM
i got a similiar question.
can i use two variables(strings) using 'in'.
i want to test if one variable is in another, so i did this:
if letter in word:
October 1st, 2005, 11:13 AM
The quickest way to answer any question like this is to try it and see. Python has a very good interactive mode, which lets you execute snippets of code and see the result immediately. It also has a very good online help mode.
Originally Posted by megazear7
I find it is often much quicker to experiment in the interactive console than to look up something in docs, let alone post a question to a forum and wait for someone to reply.
P.S. the answer to your question is YES.
October 2nd, 2005, 09:22 AM
October 2nd, 2005, 09:35 AM
it says: "reguires character as left operand" when i do it.
if guess in word:
and i cant change the two variables around becouse 'word' is a random word from a list and 'guess' is a letter the user guesses.??