471,350 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

conditional statement

I have 2 strings,
string1
string2

I'd like to make a conditional that if string2 is not in string1 print error message. How can I do that.
I tried:
Expand|Select|Wrap|Line Numbers
  1. if (string2 in string1)='False':
  2.    print 'error'
  3.  
but it did not work
Sep 18 '07 #1
4 1240
kdt
50
I have 2 strings,
string1
string2

I'd like to make a conditional that if string2 is not in string1 print error message. How can I do that.
I tried:
Expand|Select|Wrap|Line Numbers
  1. if (string2 in string1)='False':
  2.    print 'error'
  3.  
but it did not work
Expand|Select|Wrap|Line Numbers
  1. >>> str1 = 'test'
  2. >>> str2 = 'python'
  3. >>> if not str1 in str2:
  4.     print 'error'
  5.  
  6.  
  7. error
HTH
Sep 18 '07 #2
kdt
50
Hi Python101,

I saw from another of your posts that you are either a bioinformatician, or working on biological data.

Hopefully you will find some of these links useful:

Quick intro from O'Reilly with useful examples.
O'Reilly Python for Bioinformatics

Beginners guide to Python aimed at Biologists from the Pasteur Institute:
Intro Python for Biologists

More advanced, but very easy to follow tutorial from Pasteur again. Covers most of the basic analysis required, as well as more advanced parser scripts to NCBI etc.
Python for Bioinformatics

All the best
Sep 18 '07 #3
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. >>> str1 = 'test'
  2. >>> str2 = 'python'
  3. >>> if not str1 in str2:
  4.     print 'error'
  5.  
  6.  
  7. error
HTH
Yep. That's a good one. I also like the slightly more English version:
Expand|Select|Wrap|Line Numbers
  1. >>> str1 = 'test'
  2. >>> str2 = 'python'
  3. >>> if str1 not in str2:
  4.     print 'error'
  5.  
  6.  
  7. error
I also like the way this site displays code when "=python" is added inside the first CODE tag.
Sep 18 '07 #4
kdt
50
Yep. That's a good one. I also like the slightly more English version:
Expand|Select|Wrap|Line Numbers
  1. >>> str1 = 'test'
  2. >>> str2 = 'python'
  3. >>> if str1 not in str2:
  4.     print 'error'
  5.  
  6.  
  7. error
I also like the way this site displays code when "=python" is added inside the first CODE tag.
excellent, i was trying to add the tag earlier, just didn't know how!

cheers
Sep 18 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by in | last post: by
7 posts views Thread by Shaldaman | last post: by
4 posts views Thread by mux | last post: by
5 posts views Thread by paulo | last post: by
13 posts views Thread by Neal Becker | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.