conditional statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • python101
    New Member
    • Sep 2007
    • 90

    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:
    [code=python]
    if (string2 in string1)='False ':
    print 'error'
    [/code]
    but it did not work
  • kdt
    New Member
    • Mar 2007
    • 50

    #2
    Originally posted by python101
    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:
    [code=python]
    if (string2 in string1)='False ':
    print 'error'
    [/code]
    but it did not work
    Code:
    >>> str1 = 'test'
    >>> str2 = 'python'
    >>> if not str1 in str2:
    	print 'error'
    
    	
    error
    HTH

    Comment

    • kdt
      New Member
      • Mar 2007
      • 50

      #3
      Hi Python101,

      I saw from another of your posts that you are either a bioinformaticia n, 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

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by kdt
        Code:
        >>> str1 = 'test'
        >>> str2 = 'python'
        >>> if not str1 in str2:
        	print 'error'
        
        	
        error
        HTH
        Yep. That's a good one. I also like the slightly more English version:[CODE=python]>>> str1 = 'test'
        >>> str2 = 'python'
        >>> if str1 not in str2:
        print 'error'


        error[/CODE]I also like the way this site displays code when "=python" is added inside the first CODE tag.

        Comment

        • kdt
          New Member
          • Mar 2007
          • 50

          #5
          Originally posted by bartonc
          Yep. That's a good one. I also like the slightly more English version:[CODE=python]>>> str1 = 'test'
          >>> str2 = 'python'
          >>> if str1 not in str2:
          print 'error'


          error[/CODE]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

          Comment

          Working...