在Python中,数据以对象的形式存在。
Python的内置对象:
| 对象类型 | 例子 |
|---|---|
| 数字 | 1234, 3.14, 999L, 3+4j, Decimal |
| 字符串 | ‘hello world’ |
| 列表 | [1, [2, ‘three’], 4] |
| 字典 | {‘name’: ‘mo’, ‘age’: 20} |
| 元组 | (1, ‘name’, 2, ‘age’) |
| 文件 | myfile = open(‘myscript’, ‘r’) |
| 其它类型 | 集合、类型、None、布尔型 |
Python支持基本的数学运算,值得一提的是乘方运算 ,例如2100表示2的100次方。还有一些内置的数学模块可以使用,例如math和random。
import mathprint math.piprint math.sqrt(96)import randomprint random.random()print random.choice([1,2,3,4])
