(首页)开始编程之旅 翻译自Lee Harr的Start Programming

本文是使用pygsear+pygame作为开发环境,以初级用户角度来分步分阶段学习PYTHON基本概念,并以小游戏开发项目为具体案例,介绍的十分详细。编写风格清新朴实,没有象一般教科书那样枯燥,极其适合初级用户来激发兴趣时使用。

1. StartProgramming-1-8 帮助Help

We will come back to functions and sequences in the next chapter, but first I want to bring up one more thing about the interactive interpreter:

我们将在下一节中回到函数和列表中,但是首先我想中断其它的事情是因为这个交互解释器。

Notice that by typing:

注意键入:

help

python will tell you how to get help.

python将会告诉你怎样获得帮助。

Basically, it tells you to type help() with which you can enter the python help browser and get a lot of generally helpful information. Alternatively, you can put something inside the parentheses which you want to get help on. Try this:

基本上,它告诉你在可以进入的python帮助系统中键入help() 并获得一些通用的帮助信息。或者,你可以在圆括号内输入你需要获得帮助的事物。试试这个:

>>> help(range)
Help on built-in function range:

range(...)
range([start,] stop[, step]) -> list of integers

Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
These are exactly the valid indices for a list of 4 elements.

You type in the first line, after the >>>

你在第一行的>>>后面输入

help(range)

and Python will tell you about the range function.

Python就会告诉你关于range函数的帮助。

That is interesting. Let's try out the example they give:

这是很有趣的。让我们尝试一下他们给出的这个例子:

range(4)
returns: [0, 1, 2, 3]

Just like they said it would be. How about if we give range 2 numbers:

就像说将要发生的事情一样。如果我们给range两个数会怎样:

range(4, 10)
returns: [4, 5, 6, 7, 8, 9]

Notice how the list returned does include the first number you give, but it does not include the last number you give.

注意列表是怎样返回一个 包含 你给出的第一个数字,但却 不 包含你给出的最后的数字。

Now try range with 3 arguments:

现在试试有3个参数的range:

range(0, 100, 10)
returns: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]

Very nice. I wonder if we can use this to make pete perform some even more amazing tricks?

非常好。我怀疑我们是否还能够用pete做出更多令人惊奇的把戏来?

Also notice that you can get help on pete himself!

同样也要注意我们可以在pete自身上获得帮助!

Unfortunately, help(pete) only tells us that pete is an instance of the Penguin class. We can get help on pete and all of his kind with:

不幸的是,help(pete)只能告诉我们pete是一个Penguin类的实例。我们能够在pete和它所有的同类身上获得帮助:

help(Penguin)