← Back to challenges

Remove the First and Last Characters

PythonHardstringsformattinglanguage_fundamentals

Instructions

Create a function that removes the first and last characters from a string.

Examples

remove_first_last("hello") ➞ "ell"

remove_first_last("maybe") ➞ "ayb"

remove_first_last("benefit") ➞ "enefi"

remove_first_last("a") ➞ "a"

Notes

For words with two or fewer letters (including an empty string), return the string itself (see example #4).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: N Tables + 1