Skip to content

Latest commit

 

History

History
26 lines (22 loc) · 740 Bytes

File metadata and controls

26 lines (22 loc) · 740 Bytes

####变量

编程语言的一个最强大的特性就是可以操作变量(variables) 一个赋值语句创建了一个新的变量,并且为这个变量赋值:

>>> message = 'And now for something completely different'
>>> n = 17
>>> pi = 3.1415926535897931

上面的例子干了三件事,第一个创建了一个字符串变量message,第二个整型变量n,值是17,第三个将π的近似值赋值给了变量pi。

要输出一个变量的值,你可以使用print语句

>>> print(n)
17
>>> print(pi)
3.141592653589793

一个变量的类型就是变量的值所代表的类型:

>>> type(message) <class 'str'>
>>> type(n) <class 'int'>
>>> type(pi) <class 'float'>