22.6: Returning Text

The Crystal Ball - Instruction Manual I: Introduction to Data Science · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under not declared, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    22.6: Returning Text

    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.