Python Forum

Full Version: Find ? in string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been looking for a while and can't find a simple way to do this.

So, what is the quickest, simplest way to check if a string contains a ?


I don't care where it is, I just need to know if there is one.

Many thanks.
'?' in string
Hmm, can't make that work.

if '?" in mystring:
  print "Found"
else:
  print "Not found"
Output:
Not found
(Jan-17-2019, 08:01 PM)MuntyScruntfundle Wrote: [ -> ]Hmm, can't make that work.
what is the value of mystring?

for my_string in ['spam', 'eggs?']:
    print('{} --> {}'.format(my_string, '?' in my_string))
Output:
spam --> False eggs? --> True
Nobody can debug your code without the actual faulty code. We don't read in a crystal ball.
Also, the code you show cannot run because you mix single and double quotes

Error:
if '?" in mystring: ^ SyntaxError: EOL while scanning string literal