473,229 Members | 1,812 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,229 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 1327
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.