1.2.1. 第一步

Start the Ipython shell (an enhanced interactive Python shell):

  • 通过从Linux/Mac终端或从Windows cmd shell键入“ipython”,
  • 通过菜单启动程序,例如Python(x,y)EPD菜单,如果你安装了这些科学计算套件。

如果你的计算机上没有安装Ipython,也可以使用其他Python shell,例如通过在终端中输入“python”启动的纯Python shell,或者Idle解释器。However, we advise to use the Ipython shell because of its enhanced features, especially for interactive scientific computing.

Once you have started the interpreter, type

>>> print("Hello, world!")
Hello, world!

The message “Hello, world!” is then displayed. You just executed your first Python instruction, congratulations!

要自己开始,请键入以下指令

>>> a = 3
>>> b = 2*a
>>> type(b)
<type 'int'>
>>> print(b)
6
>>> a*b
18
>>> b = 'hello'
>>> type(b)
<type 'str'>
>>> b + b
'hellohello'
>>> 2*b
'hellohello'

Two variables a and b have been defined above. 请注意,在给它赋值之前,不会声明变量的类型。In C, conversely, one should write:

int a = 3;

In addition, the type of a variable may change, in the sense that at one point in time it can be equal to a value of a certain type, and a second point in time, it can be equal to a value of a different type. b was first equal to an integer, but it became equal to a string when it was assigned the value ‘hello’. 对整数(b=2*a)的操作在Python中编写起来很自然,对字符串的一些操作,如加法和乘法,分别等于连接和重复。