这里将它们按字母表顺序列出。

    Built-in Functions    
abs() divmod() input() open() staticmethod()
all() enumerate() int() ord() str()
any() eval() isinstance() pow() sum()
basestring() execfile() issubclass() print() super()
bin() file() iter() property() tuple()
bool() filter() len() range() type()
bytearray() float() list() raw_input() unichr()
callable() format() locals() reduce() unicode()
chr() frozenset() long() reload() vars()
classmethod() getattr() map() repr() xrange()
cmp() globals() max() reversed() zip()
compile() hasattr() memoryview() round() __import__()
complex() hash() min() set() apply()
delattr() help() next() setattr() buffer()
dict() hex() object() slice() coerce()
dir() id() oct() sorted() intern()

 

all(iterable)

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

staticmethod(function)

返回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

 

isinstance(object, classinfo)

TypeError异常。

issubclass(class, classinfo)

TypeError异常。

 

相关文章:

  • 2021-12-19
  • 2021-12-24
  • 2021-10-27
  • 2021-08-10
  • 2021-11-24
  • 2021-09-09
  • 2022-02-12
猜你喜欢
  • 2021-11-06
  • 2022-01-31
  • 2022-03-08
  • 2021-09-30
  • 2021-11-05
  • 2021-10-15
  • 2021-08-08
相关资源
相似解决方案