ЁЯУв Too many exams? DonтАЩt know which one suits you best? Book Your Free Expert ЁЯСЙ call Now!


    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(0, 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
    More IT Operating System Questions
    ask-question