今天研究下python 的 内建函数:
abs():Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.
绝对值,如果复数的话返回复数的模
all
(iterable)
Return True
if all elements of the iterable are true (or if the iterable is empty). Equivalent to:
New in version 2.5.
any
(iterable)
Return True
if any element of the iterable is true. If the iterable is empty, return False
. Equivalent to:
New in version 2.5.
basestring
()
This abstract type is the superclass for str
and unicode
. It cannot be called or instantiated, but it can be used to test whether an object is an instance of str
or unicode
. isinstance(obj, basestring)
is equivalent to isinstance(obj, (str, unicode))
.
New in version 2.3.
bin
(
x
)
Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int
object, it has to define an __index__()
method that returns an integer.
New in version 2.6.
bool
([x])
Return a Boolean value, i.e. one of True
or False
. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False
; otherwise it returns True
. bool
is also a class, which is a subclass of int
. Class bool
cannot be subclassed further. Its only instances are False
and True
.
New in version 2.2.1.
Changed in version 2.3: If no argument is given, this function returns False
.
bytearray
([source[, encoding[, errors]]])
Return a new array of bytes. The bytearray
class is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the str
type has, see String Methods.
The optional source parameter can be used to initialize the array in a few different ways:
- If it is unicode, you must also give the encoding (and optionally, errors) parameters;
bytearray()
then converts the unicode to bytes usingunicode.encode()
. - If it is an integer, the array will have that size and will be initialized with null bytes.
- If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.
- If it is an iterable, it must be an iterable of integers in the range
0 <= x < 256
, which are used as the initial contents of the array.
Without an argument, an array of size 0 is created.
New in version 2.6.
没看懂
callable
(object)
Return True
if the object argument appears callable, False
if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); class instances are callable if they have a __call__()
method.
chr
(
i
)
Return a string of one character whose ASCII code is the integer i. For example, chr(97)
returns the string 'a'
. This is the inverse of ord()
. The argument must be in the range [0..255], inclusive;ValueError
will be raised if i is outside that range. See also unichr()
.
classmethod
(function)
Return a class method for function.
A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
The @classmethod
form is a function decorator – see the description of function definitions in Function definitions for details.
It can be called either on the class (such as C.f()
) or on an instance (such as C().f()
). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.
Class methods are different than C++ or Java static methods. If you want those, see staticmethod()
in this section.
For more information on class methods, consult the documentation on the standard type hierarchy in The standard type hierarchy.
New in version 2.2.
Changed in version 2.4: Function decorator syntax added.

cmp
(x, y)
Compare the two objects x and y and return an integer according to the outcome. The return value is negative if x < y
, zero if x == y
and strictly positive if x > y
.
divmod
(a, b)
Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division. With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (a // b, a % b)
. For floating point numbers the result is (q, a % b)
, where q is usually math.floor(a / b)
but may be 1 less than that. In any case q * b + a % b
is very close to a, if a % b
is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b)
.
Changed in version 2.3: Using divmod()
with complex numbers is deprecated.
enumerate
(sequence, start=0)
Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration. The next()
method of the iterator returned by enumerate()
returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence:
Equivalent to:
New in version 2.3.
Changed in version 2.6: The start parameter was added.
range
(stop)
range
(start, stop[, step])
This is a versatile function to create lists containing arithmetic progressions. It is most often used in for
loops. The arguments must be plain integers. If the step argument is omitted, it defaults to 1
. If the start argument is omitted, it defaults to 0
. The full form returns a list of plain integers [start, start + step, start + 2 * step, ...]
. If step is positive, the last element is the largest start +i * step
less than stop; if step is negative, the last element is the smallest start + i * step
greater than stop. step must not be zero (or else ValueError
is raised). Example:
产生一个list,stop的数据不包含在内。step是可选,如果只有一个参数,就是stop,start没给默认从零开始。
(xrange参见另一个帖子)
capitalize()首字母大写
str.replace('needtoreplaced_char','replaced') 字符串里面的字符的替换
str.split()字符串切割
len:序列长度
max:序列中最大值
min:最小值
filter:过滤序列
>>> filter(lambda x:x%2==0, [1,2,3,4,5,6])
[2, 4, 6]
zip
([iterable, ...])
This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The returned list is truncated in length to the length of the shortest argument sequence. When there are multiple arguments which are all of the same length, zip()
is similar to map()
with an initial argument of None
. With a single sequence argument, it returns a list of 1-tuples. With no arguments, it returns an empty list.
The left-to-right evaluation order of the iterables is guaranteed. This makes possible an idiom for clustering a data series into n-length groups using zip(*[iter(s)]*n)
.
zip()
in conjunction with the *
operator can be used to unzip a list:
New in version 2.0.
map
(function, iterable, ...)
Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None
items. If function is None
, the identity function is assumed; if there are multiple arguments, map()
returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation). The iterable arguments may be a sequence or any iterable object; the result is always a list.
当第一个参数function 为 None的时候,map返回并行的多个list的tuple list,长度由最长的决定,短的list(由None type)补齐。
当function有定义的时候,会把后面的参数应用到这个function上来。
reduce
(function, iterable[, initializer])
Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
calculates ((((1+2)+3)+4)+5)
. The left argument, x, is the accumulated value and the right argument, y, is the update value from the iterable. If the optional initializer is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty. If initializer is not given and iterable contains only one item, the first item is returned. Roughly equivalent to: