这里将它们按字母表顺序列出。
True。
等同于:
def all(iterable):
for element in iterable:
if not element:
return False
return True
>>> help(all) Help on built-in function all in module __builtin__: all(...) all(iterable) -> bool Return True if bool(x) is True for all values x in the iterable. If the iterable is empty, return True. >>> listMy = ['abc','abd'] >>> all(listMy) True >>> listMy.append(False) >>> all(listMy) False
any(iterable)
False。
>>> listMy = ['abc','abd'] >>> any(listMy) True >>> listMy.append(False) >>> any(listMy) True
basestring() 用来测试一个对象是否为字符串或者u字符串
unicode))。
>>> isinstance(listMy, basestring) False >>> isintance('abc', basestring) Traceback (most recent call last): File "<pyshell#24>", line 1, in <module> isintance('abc', basestring) NameError: name 'isintance' is not defined >>> isinstance('abc', basestring) True >>> isinstance(u"准哦功能", basestring) True >>> isinstance(123, basestring) False
bin(x),
__index__()方法。
bool([x])
True。
>>> bin(2) '0b10' >>> bin(4) '0b100' >>> bool(1) True >>> bool(2) True
chr(i)
unichr()。
>>> chr(97) 'a' >>> ord('a') 97
classmethod(function)
将function包装成类方法。
声明一个类方法,使用这样的惯例:
class C(object):
@classmethod
def f(cls, arg1, arg2, ...):
...
Function definitions中的函数定义。
如果在子类上调用类方法,子类对象被传递为隐式的第一个参数。
staticmethod()。
#coding=utf-8 class C(object): @classmethod def f(cls, arg1, arg2): print arg1,arg2 C.f(1,2) C().f(2,3) # 1 2 # 2 3
返回function的一个静态方法。
要声明静态方法,请使用下面的习惯方式:
class C(object):
@staticmethod
def f(arg1, arg2, ...):
...
函数定义中函数定义的描述。
除了它的类型,实例其他的内容都被忽略。
#coding=utf-8 class C(object): @staticmethod def s(arg1, arg2): print arg1,arg2 C.s(1,2) C().s(2,3) # 1 2 # 2 3
cmp(x, y)
y,返回正数。
>>> cmp('a','b') -1 >>> cmp(1,2) -1 >>> cmp('a',2) 1 >>> lista=[1,2] >>> listb=[2] >>> cmp(lista,listb) -1 >>> cmp(1.20,1.22) -1 >>> cmp(1.23,1.2) 1
enumerate(sequence, start=0)
next()方法返回一个元组,它包含一个计数(从start开始,默认为0)和从sequence中迭代得到的值:
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter'] >>> list(enumerate(seasons)) [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')] >>> list(enumerate(seasons, start=1)) [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')] 等同于: def enumerate(sequence, start=0): n = start for elem in sequence: yield n, elem n += 1
TypeError异常。
issubclass(class, classinfo)
TypeError异常。