That is happening because you've declared the variables a and b, and after calling the function you've printed a and b which have remained unchanged.
You need to return f_name
and t_name
in the function, and then print the returned things. So, a working solution would look like this:
def format_name(f_name, t_name):
switch_name = ""
switch_name = f_name
f_name = t_name
t_name = switch_name
return f_name, t_name
a = "Cinn"
b = "Alex"
formatted = format_name(a,b)
print(formatted[0])
print(formatted[1])
But this uses way too much storage than is required, so just returning t_name
and f_name
in order, instead of f_name
and t_name` will do everything better.
def format_name(f_name, t_name):
return t_name, f_name
a = "Cinn"
b = "Alex"
formatted = format_name(a,b)
a, b = formatted
print(a)
print(b)