1,标识符及保留字
and
assert
break
class
continue
def
del
2,标准特殊字符
字符
\
\\
\'
\"
\a
\b
\e
\0
\n
\v
\t
\r
\f
\OOO
\xhh
\un
3,运算符、分隔符及特殊符号
Python 目前支持以下运算符:
+
+=
~
下边的这些可以作为表达式,列表,字典,以及语句不同部分的分隔符号:
(
4,内建类型
分类
None
数值
序列
映射
可调用类型
模块
类
类实例
文件
内部类型
5,列表的方法
方法
list(s )
s.append(x)
s.extend(t)
s.count(x)
s.index(x)
s.insert(i,x)
s.pop([i])
s.remove(x )
s.reverse()
s.sort([cmpfunc ])
6,字符串方法
方法
s.capitalize()
s.count(sub [,start [,end ]])
s.encode([encoding [,errors ]])
s.startswith(prefix [,start [,end ]])
s.endswith(suffix [,start [,end ]])
s.expandtabs([tabsize ])
s.find(sub [,start [,end ]])
s.rfind(sub [,start [,end ]])
s.index(sub [,start [,end ]])
s.rindex(sub [,start [,end ]])
s.isalnum()
s.isalpha()
s.isdigit()
s.islower()
s.isspace()
s.istitle()
s.isupper()
s.join(t)
s.center(width)
s.ljust(width )
s.rjust(width )
s.lower()
s.upper()
s.replace(old , new [,maxreplace ])
s.lstrip()
s.rstrip()
s.strip()
s.split([sep [,maxsplit ]])
s.splitlines([keepends ])
s.swapcase()
s.title()
s.translate(table [,deletechars ])
7,映射对象的方法和操作
项目
len(m)
m[k]
m[k] = x
del m[k]
m.clear()
m.copy()
m.has_key(k)
m.items()
m.keys()
m.update(b)
m.values()
m.get(k[,v])
m.setdefault(k[,v])
m.popitem()
8,用户定义函数 f 有如下属性:
属性
f.__module__
f.__doc__ 或 f.func_doc
f.__name__ 或 f.func_name
f.__dict__ 或 f.func_dict
f.func_code
f.func_defaults
f.func_globals
f.func_closure
9,方法对象的属性:
属性
m.im_self
m.im_func
m im_class
m.__doc__
m.__name__
m.__module__
小注: 当一个用户定义方法引用的是一个类方法时,不论是否绑定到类实例,它的 im_self属性都等于其 im_class 属性。
10,内建函数及内建方法
属性
b.__doc__
b.__name__
b.__self__
b.__members__
11,模块对象拥有的属性
属性
m.__dict__
m.__doc__
m.__name__
m.__file__
m.__path__
12,class对象定义的属性
属性
c.__dict__
c.__doc__
c.__name__
c.__module__
c.__bases__
13,一个代码对象 c 拥有如下只读属性
属性
c.co_argcount
c.co_code
c.co_consts
c.co_filename
c.co_firstlineno
c.co_flags
c.co_lnotab
c.co_name
c.co_names
c.co_nlocals
c.co_stacksize
c.co_varnames
14,Frame 对象拥有如下只读属性
属性
f.f_back
f.f_code
f.f_locals
f.f_globals
f.f_builtins
f.f_restricted
f.f_lineno
f.f_lasti
可改变的属性:
f.f_trace
f.f_exc_type
f.f_exc_value
f.f_exc_traceback
15,traceback 对象
属性
t.tb_next
t.tb_frame
t.tb_lineno
t.tb_lasti
16,对象创建,删除,表示使用的特殊方法
方法
__init__(self[,args])
__del__(self)
__repr__(self)
__str__ (self)
__cmp__(self,other)
__hash__(self)
__nonzero__(self)
17,访问属性的方法
方法
__getattr__(self , name)
__setattr__(self , name , value)
__delattr__(self , name)
18,序列和映射的方法
方法
__len__(self)
__getitem__(self , key)
__setitem__(self , key , value)
__delitem__(self , key)
__getslice__(self ,i ,j)
__setslice__(self ,i ,j ,s)
__delslice__(self ,i ,j)
__contains__(self ,obj)
19,数学操作的方法
Method
__add__(self ,other)
__sub__(self ,other)
__mul__(self ,other)
__div__(self ,other)
__mod__(self ,other)
__divmod__(self ,other)
__pow__(self ,other [,modulo]) self ** other , pow(self , other , modulo)
__lshift__(self ,other)
__and__(self ,other)
__or__(self ,other)
__xor__(self ,other)
__radd__(self ,other)
__rsub__(self ,other)
__rmul__(self ,other)
__rdiv__(self ,other)
__rmod__(self ,other)
__rdivmod__(self ,other)
__rpow__(self ,other)
__rlshift__(self ,other)
__rand__(self ,other)
__ror__(self ,other)
__rxor__(self ,other)
__iadd__(self ,other)
__isub__(self ,other)
__imul__(self ,other)
__idiv__(self ,other)
__imod__(self ,other)
__ipow__(self ,other)
__iand__(self ,other)
__ior__(self ,other)
__ixor__(self ,other)
__ilshift__(self ,other)
__neg__(self)
__pos__(self)
__abs__(self)
__invert__(self)
__int__(self)
__long__(self)
__float__(self)
__complex__(self)
__oct__(self)
__hex__(self)
__coerce__(self ,other)
20,比较方法
方法
__lt__(self ,other )
__ge__(self ,other )
__eq__(self ,other )
__ne__(self ,other )
21,内建数据类型使用的内存大小
类型
Integer
Long integer
Floats
Complex
List
Tuple
String
Unicode string
Dictionary
Class instance
Xrange object
22,数值操作
运算
x + y
x - y
x * y
x / y
x // y
x ** y
x % y
-x
+x
~x
23,位运算符
操作
x x >> y
x & y
x | y
x ^ y
~x
24,内建函数支持所有的数值类型
函数
abs(x )
divmod(x ,y )
pow(x ,y [,modulo ])
round(x ,[n])
25,序列运算
操作
s + r
s * n , n * s
s % d
s[i]
s[i :j ]
x in s , x not in s
for x in s :
len(s)
min(s)
max(s)
26,字符串格式转换
字符
d,i
u
o
x
X
f
e
E
g,G
s
r
c
%
27,字典的操作
操作
x = d[k ]
d [k ] = x
del d[k ]
len(d )
28,增量赋值语句
操作
x += y
x -= y
x *= y
x /= y
x **= y
x %= y
x &= y
x |= y
x ^= y
x >>= y
29,类型转换
函数
int(x [,base ])
long(x [,base ])
float(x )
complex(real [,imag ])
str(x )
repr(x )
eval_r(str )
tuple(s )
list(s )
chr(x )
unichr(x )
ord(x )
hex(x )
oct(x )
30,Unicode编码参数
值
'ascii'
'latin-1' or 'iso-8859-1'
'utf-8'
'utf-16'
'utf-16-le'
'utf-16-be'
'unicode-escape'
'raw-unicode-escape'
31,布尔表达式
操作符
x or y
x and y
not x
32,运算优先级
运算
--------------------------------------------------------------------
(...), [...], {...}
--------------------------------------------------------------------
`...`
--------------------------------------------------------------------
s[i ], s[i:j ],
--------------------------------------------------------------------
f(...)
--------------------------------------------------------------------
+x , -x , ~x
--------------------------------------------------------------------
x ** y
--------------------------------------------------------------------
x * y , x / y , x % y
--------------------------------------------------------------------
x + y , x - y
--------------------------------------------------------------------
x > y
--------------------------------------------------------------------
x & y
--------------------------------------------------------------------
x ^ y
--------------------------------------------------------------------
x | y
--------------------------------------------------------------------
x x > y , x >= y ,
x == y , x != y
x
x is y , x is not y
x in s , x not in s
--------------------------------------------------------------------
not x
--------------------------------------------------------------------
x and y
--------------------------------------------------------------------
x or y
--------------------------------------------------------------------
lambda args : expr
33,内建异常类型
异常
Exception
SystemExit
StandardError
ArithmeticError
FloatingPointError
OverflowError
ZeroDivisionError
AssertionError
AttributeError
EnvironmentError
IOError
OSError
WindowsError
EOFError
ImportError
KeyboardInterrupt
LookupError
IndexError
KeyError
MemoryError
NameError
UnboundLocalError
RuntimeError
NotImplementedError
SyntaxError
TabError
IndentationError
SystemError
TypeError
ValueError
UnicodeError
34,文件方法
方法
f.read([n])
f.readline([n])
f.readlines()
f.xreadlines()
f.write(s)
f.writelines(l)
f.close()
f.tell()
f.seek(offset [, where])
f.isatty()
f.flush()
f.truncate([size])
f.fileno()
f.readinto(buffer ,nbytes)读取 n 字节数据至一个 buffer 对象。
stdin对象为解释器提供输入字符流。
stdout对象接收 print 语句产生的输出.
stderr对象接收出错信息.
通常stdin被映射到用户键盘输入,而stdout和stderr产生屏幕输出.
通过对 print 语句添加 >>file 修饰能够将输出内容重定向到 file 文件对象
35,对象持久化
Pickle 模块的 dump 方法可以方便的把一个对象保存到一个文件中.例如:
import Pickle object = someObject() f = open(filename,'w') Pickle.dump(object, f) # 保存对象
之后可以用 load 方法重新得到该对象:
import Pickle f = open(filename,'r') object = Pickle.load(f) # 恢复对象
36,解释器选项
python [option] ... [-c cmd | -m mod | file | -] [arg] ...
选项
-d 或 PYTHONDEBUG=x
-h
-i 或 PYTHONINSPECT=x
-O 或 PYTHONOPTIMIZE=x
-OO
-S
-t
-tt
-u 或 PYTHONUNBUFFERED=x
-U
-v 或 PYTHONVERBOSE=x
-V
-x
-c cmd
-W arg
-E
-m mod
-Q arg
file
-
arg ...
37,解释器还读取以下的环境变量:
变量
PYTHONPATH
PYTHONSTARTUP
PYTHONHOME
PYTHONINSPECT
PYTHONUNBUFFERED
PYTHONCASEOK