您在這裡

The first program

2 九月, 2015 - 17:52

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, which doesn’t actually print anything on paper. It displays a value 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.

In Python 3, the syntax for printing is slightly different:

print('Hello, World!')

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

For the rest of this book, I’ll use the print statement. If you are using Python 3, you will have to translate. But other than that, there are very few differences we have to worry about.