473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1332
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

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

Similar topics

8
by: neblackcat | last post by:
Would anyone like to comment on the following idea? I was just going to offer it as a new PEP until it was suggested that I post it here for comment & consideration against PEP 308. I'm far...
7
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
2
by: in | last post by:
In Visual Studio, is there a way of marking a statement as a "conditional run". Sort of like a breakpoint, but there, in the debugger, the statement will not execute. I'm thinking of code...
7
by: Shaldaman | last post by:
I have an Access form called "Login". "Command10" is a button on the form and "Text5" is a text field on it. When a user enters a value in the Text5 text field and clicks the button Command10, I...
4
by: mux | last post by:
Hi I found out that the following piece of code throws an error. 1 #include "stdio.h" 2 3 int main() 4 { 5 int a,b; 6 a= 10;
9
by: Marty | last post by:
Hi, Does using the the conditional operator (?:) instead of the common "if" statement will give a performance gain in a C# .NET 2003 application (even in C# .NET 2005?). What is the advantage...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
13
by: Neal Becker | last post by:
In hindsight, I am disappointed with the choice of conditional syntax. I know it's too late to change. The problem is y = some thing or other if x else something_else When scanning this my...
7
by: tiptap | last post by:
Hey Guys, I have a huge statement loads of if statements in... and its getting bigger. On closer inspection there is only 3 difference in the select statement. so I thought I could cut the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.