πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      Complete the Python function to return the last n

      characters of a string s. If n is greater than the string's length, return the entire string. def get_last_n_chars(s, n): Β  Β  _________ # Line to complete
      A return s[len(s)-n:] Correct Answer Incorrect Answer
      B return s[-n:] Correct Answer Incorrect Answer
      C return s.substring(len(s)-n) Correct Answer Incorrect Answer
      D return s.slice(-n) Correct Answer Incorrect Answer
      E return s[max(1, len(s)-n):] Correct Answer Incorrect Answer

      Solution

      Correct Answer: B (Python's negative slicing handles the case where n is greater than len(s) gracefully by returning the entire string.)

      Practice Next
      ask-question