The function f(x) takes a string input. If the string consists only of digits, it remains unchanged. Otherwise, it returns the input string with the first and last characters swapped.

