title: Python string issue when checking the first and last character
body: <p>This is the question:- Modify the first_and_last function so that it returns True if the first letter of the string is the same as the last letter of the string, False if they’re different. Remember that you can access characters using message[0] or message[-1].
  Be careful how you handle the empty string, which should return True since nothing is equal to nothing.</p>
  <p>when i write the code like this:-</p>
  <pre><code>def first_and_last(message):
  
      if len(message) == 0:
          return True
      elif message[0] == message[-1]:
          return True
      else:
          return False
  
  
  print(first_and_last(&quot;else&quot;))
  
  print(first_and_last(&quot;tree&quot;))
  
  print(first_and_last(&quot;&quot;))
  
  # output:-
  
  True
  
  False 
  
  True
  </code></pre>
  <p>But when i write the code like this:-</p>
  <pre><code>def first_and_last(message):
  
      if message[0] == message[-1]:
          return True
      elif len(message) == 0:
          return True
      else:
          return False
  
  print(first_and_last(&quot;else&quot;))
  
  print(first_and_last(&quot;tree&quot;))
  
  print(first_and_last(&quot;&quot;))
  
  # output:-
  True
  
  False
  
  Traceback (most recent call last):
    File &quot;C:/Users/Sidje/PycharmProjects/untitled2/SId.py&quot;, line 11, in &lt;module&gt;
      print(first_and_last(&quot;&quot;))
    File &quot;C:/Users/Sidje/PycharmProjects/untitled2/SId.py&quot;, line 2, in first_and_last
      if message[0] == message[-1]:
  IndexError: string index out of range
  </code></pre>
  <p>when i write the len fucntion with elif, the program is not working when the statement is empty but it works for the other conditions.
  why is that?</p>