1.3: The first program

Think Python 2ed. · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    1.3: The first program

    Traditionally, the first program you write in a new language is called “Hello, World!” because all it does is display the words “Hello, World!”. In Python, it looks like this:

    >>> print('Hello, World!')
    

    This is an example of a print statement, although it doesn’t actually print anything on paper. It displays a result on the screen. In this case, the result is the words

    Hello, World!
    

    The quotation marks in the program mark the beginning and end of the text to be displayed; they don’t appear in the result.

    The parentheses indicate that print is a function. We’ll get to functions in Chapter 3.

    In Python 2, the print statement is slightly different; it is not a function, so it doesn’t use parentheses.

    >>> print 'Hello, World!'
    

    This distinction will make more sense soon, but that’s enough to get started.


    This page titled 1.3: The first program was last modified on Tue, 01 Dec 2020 03:31:13 GMT and is shared under a CC BY-NC 3.0 license and was authored, remixed, and/or curated by Allen B. Downey (Green Tea Press) via source content that was edited to the style and standards of the LibreTexts platform.