内置函数
1.abs
def abs(*args, **kwargs): # real signature unknown
""" Return the absolute value of the argument. """
pass
翻译:返回参数的绝对值
1 #!/usr/bin/python 2 print(abs(-2)) #绝对值View Code
2.all
def all(*args, **kwargs): # real signature unknown
"""
Return True if bool(x) is True for all values x in the iterable.
If the iterable is empty, return True.
"""
pass
翻译:如果在可迭代里面所有值的bool值都是True,则返回True
如果可迭代对象为空,则返回True
1 #!/usr/bin/python 2 x=all([2,1]) #返回所有元素非假(0)为True, 3 print(x) 4 x=all([]) #返回所有元素非假(0)为True, 5 print(x)View Code
3.any
def any(*args, **kwargs): # real signature unknown
"""
Return True if bool(x) is True for any x in the iterable.
If the iterable is empty, return False.
"""
pass
翻译:如果在可迭代对象里面任何一个值的bool值为True,则返回True
如果可迭代对象为空,则返回False
1 #!/usr/bin/python 2 x=any([0,1]) #只要有真即为真 3 print('any:',x) 4 x=any([]) #只要有真即为真 5 print('any:',x)View Code
4.bin
def bin(*args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
"""
Return the binary representation of an integer.
>>> bin(2796202)
'0b1010101010101010101010'
"""
pass
翻译:返回一个数字的二进制值
1 #!/usr/bin/python 2 x=bin(1234) 3 print(x)View Code
5.chr
def chr(*args, **kwargs): # real signature unknown
""" Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. """
pass
翻译:返回一个带有序号的字符串的unicode字符#返回对应的字符
1 #!/usr/bin/python 2 print(chr(97))View Code
6.ord
def ord(*args, **kwargs): # real signature unknown
""" Return the Unicode code point for a one-character string. """
pass
翻译:为单字符字符串返回一个对应的unicode编码值,即返回一个数字
1 #!/usr/bin/python 2 print(ord('a'))View Code
7.oct/hex
def hex(*args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
"""
Return the octal/hexadecimal representation of an integer.
>>> hex(12648430)
'0xc0ffee'
"""
翻译:返回一个整数的八进制或者十六进制表达形式
1 #!/usr/bin/python 2 print(oct(123)) 3 print(hex(123))View Code
8.filter
class filter(object):
"""
filter(function or None, iterable) --> filter object
Return an iterator yielding those items of iterable for which function(item)
is true. If function is None, return the items that are true.
"""
翻译:如果函数里面每个对象都是True,返回一个可迭代对象的生成器。如果函数为空,这返回对象里面每个为True的值。注意返回的是对象里面不为False的值
1 #!/usr/bin/python 2 x=filter(None,[0,1,2,3,4]) #返回为True的值[1,2,3,4] 3 for i in x: 4 print(i) 5 x=filter(lambda x:x-1 ,[0,1,2,3,4])#经过lambda转换后,都不为0,所以返回所有值,即[0,1,2,3,4] 6 for i in x: 7 print(i)View Code
9.enumerate
The enumerate object yields pairs containing a count (from start, which
defaults to zero) and a value yielded by the iterable argument.
enumerate is useful for obtaining an indexed list:
| (0, seq[0]), (1, seq[1]), (2, seq[2]), ..
翻译:enumerate对象生成一对包含数字(从start值开始,默认为0)和可迭代对象参数的值
enumerate 对含有索引的列表非常有用如 (0, seq[0]), (1, seq[1]), (2, seq[2]), ..
1 #!/usr/bin/python 2 for i in enumerate([1,2,3]): 3 print('enumerate-------------------',i)View Code
10.eval
def eval(*args, **kwargs): # real signature unknown
"""
Evaluate the given source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
"""
pass
翻译:在全局和局部内容里面计算被给的源代码
源代码可能是一个python表达式的字符串或者可编译的作为被返回的代码对象。 全局必须是一个字典,局部可以是任意映射,默认为当前的全局变量和局部变量
如果只给了全局变量,那么局部默认也是它
1 #!/usr/bin/python 2 print(eval('1+1'))View Code
11.exec
def exec(*args, **kwargs): # real signature unknown
"""
Execute the given source in the context of globals and locals.
The source may be a string representing one or more Python statements
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
"""
pass
翻译:在给定的全局变量和局部变量内容种执行给定的原代码
源代码必须是一个或多个python语句的字符串或者可编译的作为返回值的代码对象
全局变量必须是字典,局部变量可能是任意的映射,默认是当前的全局变量和局部变量,
如果只给了全局变量,那么局部变量默认也是它
1 #!/usr/bin/python 2 exec('for i in range(3):print(i)')View Code
12.hash
def hash(*args, **kwargs): # real signature unknown
"""
Return the hash value for the given object.
Two objects that compare equal must also have the same hash value, but the
reverse is not necessarily true.
"""
pass
翻译:返回给定对象的hash值
两个比较对象相等那么必须有相同的hash值,但是反过来未必是真的
1 #!/usr/bin/python 2 print('hash---------',hash('123')) 3 print('hash---------',hash('123'))View Code
13.globals()
def globals(*args, **kwargs): # real signature unknown
"""
Return the dictionary containing the current scope's global variables.
NOTE: Updates to this dictionary *will* affect name lookups in the current
global scope and vice-versa.
"""
pass
翻译:返回一个字典包含当前所有全局变量。
1 #!/usr/bin/python 2 print(globals())View Code
14.locals()
def locals(*args, **kwargs): # real signature unknown
"""
Return a dictionary containing the current scope's local variables.
NOTE: Whether or not updates to this dictionary will affect name lookups in
the local scope and vice-versa is *implementation dependent* and not
covered by any backwards compatibility guarantees.
"""
pass
翻译:返回一个字典包含当前作用域的局部变量
1 #!/usr/bin/python 2 print(locals())View Code
15.id
def id(*args, **kwargs): # real signature unknown
"""
Return the identity of an object.
This is guaranteed to be unique among simultaneously existing objects.
(CPython uses the object's memory address.)
"""
pass
翻译:返回一个对象的标识
这为了确保存在对象的唯一性(cpythony用的是对象内存地址)
1 #!/usr/bin/python 2 print('id-------------',id(['abc'])) 3 x=['abc'] 4 print(id(x))View Code
16.iter
def iter(source, sentinel=None): # known special case of iter
"""
iter(iterable) -> iterator
iter(callable, sentinel) -> iterator
Get an iterator from an object. In the first form, the argument must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the sentinel.
"""
pass
翻译:将可迭代对象转换为迭代器
从一个对象获取一个迭代器,在第一个参数必须自己是一个迭代器,或者是一个序列
第二个参数,可调用对象被调用时返回这个参数时则停止。
1 #!/usr/bin/python 2 import random 3 def test(): 4 return random.randint(0,9) 5 x=iter(test,5) 6 for i in x: 7 try: 8 print(i) 9 except StopIteration: 10 exit()View Code
17.map
class map(object):
"""
map(func, *iterables) --> map object
Make an iterator that computes the function using arguments from
each of the iterables. Stops when the shortest iterable is exhausted.
"""
翻译:生成一个迭代器,用每个来自可迭代对象的参数计算函数,当最小的可迭代对象用完,则停止
1 #!/usr/bin/python 2 def test(i): 3 return i+1 4 x=map(test,[1,2,3,4]) 5 for i in x: 6 print(i)View Code
18.reversed
class reversed(object):
""" Return a reverse iterator over the values of the given sequence. """
翻译:返回与给定序列值的反向迭代器,返回为一个迭代器
1 #!/usr/bin/python 2 test =reversed([1,2,3,4,5]) #反向迭代器 3 print(type(test))#<class 'list_reverseiterator'> 4 for i in test: 5 print(i)View Code
19.zip
class zip(object):
"""
zip(*iterables) --> A zip object yielding tuples until an input is exhausted.
>>> list(zip('abcdefg', range(3), range(4)))
[('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]
The zip object yields n-length tuples, where n is the number of iterables
passed as positional arguments to zip(). The i-th element in every tuple
comes from the i-th iterable argument to zip(). This continues until the
shortest argument is exhausted.
"""
翻译:zip对象生成具有n长度的数组,这个n是可迭代对象的数字作为位置参数传给zip,第i个元素在每个元组来自用于第i个可迭代参数给zip.这会持续到最短的参数用完。
如例子里面的list(zip('abcdefg',range(3),range(4)),中有3个位置参数,则n=3,然后每个位置参数的可迭代值依次进入元组,最短的长度位range(3)值只有0,1,2
三个,所以就只迭代3次。
1 #!/usr/bin/python 2 x=list(zip('abcdefg',[1,2],[2,3])) 3 print(x) 4 x=list(zip('abcde',range(4),range(3)))View Code
标签:bin,Code,函数,之内,python,usr,print,View From: https://www.cnblogs.com/Little-Girl/p/17985398