Python Forum
Find ? in string - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Find ? in string (/thread-15448.html)



Find ? in string - MuntyScruntfundle - Jan-17-2019

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.


RE: Find ? in string - micseydel - Jan-17-2019

'?' in string



RE: Find ? in string - MuntyScruntfundle - Jan-17-2019

Hmm, can't make that work.

if '?" in mystring:
  print "Found"
else:
  print "Not found"
Output:
Not found



RE: Find ? in string - buran - Jan-17-2019

(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



RE: Find ? in string - Gribouillis - Jan-17-2019

Nobody can debug your code without the actual faulty code. We don't read in a crystal ball.


RE: Find ? in string - buran - Jan-17-2019

Also, the code you show cannot run because you mix single and double quotes

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