Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Find ? in string
#1
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.
Quote
#2
'?' in string
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#3
Hmm, can't make that work.

if '?" in mystring:
  print "Found"
else:
  print "Not found"
Output:
Not found
Gribouillis wrote Jan-17-2019, 08:03 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

I fixed for you this time. Please use code tags on future posts.
Quote
#4
(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
Quote
#5
Nobody can debug your code without the actual faulty code. We don't read in a crystal ball.
buran likes this post
Quote
#6
Also, the code you show cannot run because you mix single and double quotes

Error:
if '?" in mystring: ^ SyntaxError: EOL while scanning string literal
micseydel likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Help to find a string and read the next lines crlamaral 4 313 Mar-19-2020, 09:24 AM
Last Post: Larz60+
  How To Find an Opening and Closing String, Copying Open/Close/Contents to New File davidshq 1 236 Mar-03-2020, 04:47 AM
Last Post: davidshq
  How to Find & Count String Patterns Between two Markers in a HTML file ahmedwaqas92 3 462 Aug-19-2019, 10:12 AM
Last Post: ahmedwaqas92
  Find string and add character - newbi PyDK 1 363 May-15-2019, 01:22 PM
Last Post: ichabod801
  How can I find a string in sequence (with Booleans)? go127a 3 481 Apr-23-2019, 01:58 PM
Last Post: ichabod801
  String Method 'find(...)'. ClassicalSoul 3 532 Feb-27-2019, 12:24 PM
Last Post: buran
  Find closest string pattern jmair 9 880 Dec-12-2018, 09:17 PM
Last Post: jmair
  How to find previous string of a string Prince_Bhatia 1 769 Sep-26-2018, 02:31 PM
Last Post: gruntfutuk
  How Do I find Index of a character in string? ilcaa72 5 1,012 May-23-2018, 11:44 PM
Last Post: wavic
  Beginner Q: failure to find string in list Jenny 2 785 Mar-18-2018, 01:07 PM
Last Post: Jenny

Forum Jump:


Users browsing this thread: 1 Guest(s)