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
  How to Find & Count String Patterns Between two Markers in a HTML file ahmedwaqas92 3 216 Aug-19-2019, 10:12 AM
Last Post: ahmedwaqas92
  Find string and add character - newbi PyDK 1 210 May-15-2019, 01:22 PM
Last Post: ichabod801
  How can I find a string in sequence (with Booleans)? go127a 3 301 Apr-23-2019, 01:58 PM
Last Post: ichabod801
  String Method 'find(...)'. ClassicalSoul 3 347 Feb-27-2019, 12:24 PM
Last Post: buran
  Find closest string pattern jmair 9 570 Dec-12-2018, 09:17 PM
Last Post: jmair
  How to find previous string of a string Prince_Bhatia 1 591 Sep-26-2018, 02:31 PM
Last Post: gruntfutuk
  How Do I find Index of a character in string? ilcaa72 5 824 May-23-2018, 11:44 PM
Last Post: wavic
  Beginner Q: failure to find string in list Jenny 2 599 Mar-18-2018, 01:07 PM
Last Post: Jenny
  Python find the minimum length of string to differentiate dictionary items zydjohn 3 992 Mar-03-2018, 05:23 PM
Last Post: Gribouillis
  find a character in a string in python3 tony1812 6 2,633 Sep-27-2017, 03:28 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)