title: How to check value in a loop?
body: <p>I have a code to print the last line of a file (update real time) in a while loop. What I want to do is to check &quot;data&quot; is not the same as in the last loop, so that it won't print duplicated text. How do I achieve that?</p>
  <p>I want to do something like this:</p>
  <pre><code>starttime = time.time()
  
  while True:
      with open('test.txt', 'r') as f:
          lines = f.read().splitlines()
          last_line = lines[-1]
          if data is not last_line:
              data=last_line
      print(data)
      time.sleep(1 - ((time.time() - starttime) % 1))
  </code></pre>