How to query python list with multiple characters in each one
<p>I know the title is a little messy and if someone wants to fix it, they are more than welcome to.</p>

<p>Anyways, I'm having trouble querying a python list with multiple values, I have looked on other Stackoverflow questions and none of seem to match what I'm looking for.</p>

<p>So, this is the code I have so far, its supposed to use a for loop statement, so that it goes through each character and then uses and if in statements to check whether a character in the user input matches anything in the list.</p>

<p>In my example, it only uses symbols, but hopefully that shouldn't be much of a problem</p>

<p>Anyways here is the code</p>

<pre><code>string = input("What symbol character would you like to check")
symbols=[' ', '!', '#', '$', '%', '&amp;', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '&lt;', '=', '&gt;', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]
def symbol():
    for string in symbols:
        if string in symbols:
            return True
        elif string not in symbols:
            return False

if symbol():
    print('ok')
if not symbol():
    print('What Happened?')
</code></pre>

<p>*Update, I also need solution to be able to accept letters and numbers as well as the symbols.</p>

<p>For example, if user enters !a, that it will still detect the '!' and evaluate to True.</p>

<p>If you loop over the input string, you should be able to get the solution you're looking for.  How about something like this?</p>

<pre><code>input_string = raw_input("What symbol character would you like to check? ")
symbols = [' ', '!', '#', '$', '%', '&amp;', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '&lt;', '=', '&gt;', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]
def symbol(input_str):
    for char in input_str:
        if char in symbols:
            return True
    return False

if symbol(input_string):
    print('ok')
else:
    print('What Happened?')
</code></pre>

<p><code>raw_input()</code> avoids some trouble.  Before I changed that, I was getting an <code>unexpected EOF while parsing</code> error.  I changed the names of your variables to help a bit and avoid potential conflicts.</p>

<p>By moving the <code>return False</code> line outside the <code>for</code> loop, it lets the loop check every character in the input string first.  If it checks every one, and nothing matches, then it will default to returning <code>False</code>.</p>

<p>Also, you have two calls to <code>symbol()</code> in your question, which I don't think is necessary.  One <code>if</code> can check for a <code>True</code> return value.  Lacking that, we move to the <code>else</code> statement and can safely know that the function returned <code>False</code>.</p>

python list if-statement condition