Skip to main content
Engineering LibreTexts

22.6: Returning Text

  • Page ID
    88722
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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 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; a detailed edit history is available upon request.