Opening the book…
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.)
This page titled 22.6: Returning Text was last modified on Sun, 18 Sep 2022 02:06:25 GMT and is shared under a not declared license and was authored, remixed, and/or curated by Stephen Davies (allthemath.org) via source content that was edited to the style and standards of the LibreTexts platform.
The book could not be loaded just now.