Swap the Ends
This function helps you practice careful work with the first and last characters of a string. Write a function front_back that takes a string s and returns a new string where the first and last characters have been swapped. If the string has fewer than two characters, there is nothing to swap, so return it unchanged.
Примеры
Ввод
"code"Вывод
"eodc"Ввод
"a"Вывод
"a"Ввод
""Вывод
""Нужно реализовать
def front_back(s: str) -> str:
Теги
strings
Inicia sesión para ver tu historial de envíos
Iniciar sesiónInicia sesión para usar el AI Mentor
Iniciar sesiónVisible tests
1
Input
"code"Expected
"eodc"2
Input
"a"Expected
"a"3
Input
""Expected
""4
Input
"ab"Expected
"ba"5
Input
"edoc"Expected
"cdoe"6
Input
"codecode"Expected
"eodecodc"Focus radio
Paused · SomaFM · Fluid