What is "if not" in python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Person009
    New Member
    • Mar 2012
    • 1

    What is "if not" in python?

    For example what does the third line mean?

    Code:
    contents = open("file.dat").read()
    for line in contents.split("*"):
      if not line: continue  # Remove initial empty string.
      line = line.strip()   # Remove whitespace from beginning/end of lines.
      items = line.split("-")
      print items[0], ":", " ".join(items[1:])
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    it means that if line does not contain anything it continues to the next iteration of the loop

    Comment

    • eGrove Systems
      New Member
      • Dec 2012
      • 6

      #3
      'If not' is a condition which is used to check whether the list is empty or not
      for example:
      Code:
               lister=[]
               if not lister:
                      print "list is in empty"
      Last edited by bvdet; Dec 14 '12, 02:18 PM. Reason: Add code tags

      Comment

      • maya29988
        New Member
        • May 2014
        • 7

        #4
        if not <condition> in python is equal to if (!<condition>) in c.

        Comment

        • Hellstorm6X
          New Member
          • May 2014
          • 1

          #5
          It's really an easy concept.

          Comment

          Working...