22.6: Returning Text
- Page ID
- 88722
So far, our functions have returned numeric answers. But they can certainly return text as well. Here’s a function which assembles a person’s full name out of his or her constituent components:
Code \(\PageIndex{1}\) (Python):
def full_name(last_name, first_name, middle_initial):
return first_name + " " + middle_initial + ". " + last_name
my_full_name = full_name("Davies", "Stephen", "C")
her_full_name = full_name("Clinton", "Hillary", "R")
print("Your author's full name is: {}".format(my_full_name))
print("Another person's full name is: {}".format(her_full_name))
| Your author's full name is: Stephen C. Davies
| Another person's full name is: Hillary R. Clinton
(Recall that the “+” operator is used for the concatenation of strings.)