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
Logi sisse, et näha esituste ajalugu
Logi sisseLogi sisse, et kasutada AI mentorit
Logi sisseVisible 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