title: Python: How to break the loop if character limit is met?
body: <p>I am creating a string that must be exactly 140 characters long. I must use  a loop with a break statement, and the string items are taken from the given list. </p>
  
  <p>In the end, I managed to get to 147 characters. Is there a way to truncate the string?</p>
  
  <pre><code>headlines = ["Local Bear Eaten by Man",
               "Legislature Announces New Laws",
               "Peasant Discovers Violence Inherent in System",
               "Cat Rescues Fireman Stuck in Tree",
               "Brave Knight Runs Away",
               "Papperbok Review: Totally Triffic"]
  
  news_ticker = ""
  
  for headline in headlines:
      if len(str(news_ticker)) &gt;= 140:
          break
      else:
          news_ticker = list(news_ticker)
          news_ticker.append(headline)
  
  print(news_ticker)
  print(len(str(news_ticker)))
  </code></pre>