//数字与表达式
>>>2+2
4
>>>1/2
0
>>>1.0/2.0(1.0/2 | 1/2.0)
0.5
//执行整除,用双斜杠
>>>1//2
0
>>>1.0//2.0
0
>>>1%2
1
//十六进制和八进制
>>>0xAF
175
>>>010
8
//幂运算
>>>2**3
8
//设置变量
>>>x=3
>>>x*2
6
//语句
>>>print ("Hello,world!")
Hello,world!
//获取用户输入
>>>input("The meaning of life:")
The meaning of life:42
42
>>>x = input("x: ")
x:34
>>>y = input("y: ")
y:42
>>>print x*y
1428
//if语句(回车两次才能执行)
>>>if 1==2: print 'One equals two'
...
>>>if 1==1: print 'One equals one'
...
One equals one
//函数
>>>pow(2,3)
8
>>>abs(-10)
10
>>>round(1.0/2.0)//四舍五入
1.0
//模块
>>>import math
>>>math.floor(32.9)//向下取整、ceil向上取整
32.0
>>>int(math.floor(32.9))
32
//不用带上模板的名字(或者 foo=math.sqrt 用foo来代替)
>>>from math import sqrt
>>>sqrt(9)
3.0
//处理复数
>>>import cmath
>>>cmath.sqrt(-1)
1j
//字符串的拼接
>>>x = "Hello,"
>>>y = "world!"
>>>x+y
'Hello,world!'
>>>"Hello,"+"world!"
//长字符换行
>>>print '''This is
a very long
sentence'''
This is a very long sentence
>>>print "Hello,\
world!"
'Hello,world!'
//原始字符串
>>>print 'C:\nowhere'
C:
owhere
>>>print r'C:\nowhere'
C:\nowhere