Python Built-in Functions
重点复习对象
map, filter & reduce
map
Celsius = [39.2, 36.5, 37.3, 37.8]
Fahrenheit = map(lambda x: (float(9)/5) * x + 32, Celsius)
filter
fib = [0,1,1,2,3,5,8,13,21,34,55]
result = filter(lambda x: x % 2, fib)
reduce
s = reduce(lambda x, y: x+y, [47,11,42,13])
join()
使用join()
的时候, array里的element要是str
Math 类
- abs()
- min()
- max()
- round()
- divmod(a, b)
- float()
- hex()
- int()
- oct()
- pow(x, y[, z])
Type Cast类
- bin()
convert an integer
number to a binary
string
- chr() vs ord()
- bool()
- bytearray
- bytes
- dict()
- str()
iterable 类
- all(iterable)
return True
if all elements of the iterable are true
- any(iterable)
return True
if any element ...
- enumerate(iterable, start=0)
- filter(function, iterable)
- map(function, iterable)
- reduce(function, iterable)
- iter(object[, sentinel])
- next()
retrieve the next item from the iterator
by calling its
__next__()
method.
- reversed()
- set()
- slice()
- sorted()
- sum()
- tuple()
- zip(iterable)
- repr()
- ascii()
as repr()
, return a string containing a printable representation
of an object, but secape the non-ASCII chars.
- format()
class, object
- delattr(object, name)
- setattr(object, name)
- getattr(object, name[, default])
- hashattr(object, name)
- hash(object)
- id(object)
- type(object)
- vars([object])
- dir([object])
return the list of names in the current local scope
return the __dict__
attribute for a module, class, instance or
any other object with a dict attribute.
- isinstance(object, classinfo)
- issubclass(class, classinfo)
- staticmethod(function)
- complex()
其他
- compile()
- locals()
- globals()
- eval()
- exec()
- len()
range()
input([prompt])
- open()
print()
import(...)
the function reads a line form input, converts it to a string(stripping a trailing newline), and returns that