python基础7之python3的内置函数
官方介绍: python3:https://docs.python.org/3/library/functions.html?highlight=built#ascii python2:https://docs.python.org/2/library/functions.html?highlight=built#ascii 下面介绍python3中具体每个内置函数的使用方法及含义;
>>> abs(-11
>>> abs(-2.52.5
True,如果有一个为假的那么就返回 >>>>>> all([1,2,3,>>> all({:1,:
>>> any([1,3>>> any([0,3>>>>>> any([-1>>> any([-1>>>
>>> repr(
>>> repr(123
>>> repr([1,3
__repr__方法,获取返回值。 >>> >>>
>>> b=>>>
>>>< >
__index__()并且返回值为 >>> bin(8
>>> x=bin(9>>>< >
>>> bool(1>>>>>> bool([1,2>>> bool([0,3>>>
>>> bytearray(1>>> bytearray([1,3>>> bytearray(,encoding=)
sourceencodingerrors >>>
>>> bytes(1
>>> bytes([1,3
>>> callable( x:x*2>>>>>> callable([1,3
>>> chr(99
>>> chr(98
>>> str=
>>> a=compile(str,,>>>
>>> complex(1,21+2j>>> complex(11+>>> complex(1+2j)
>>> (>>> a=>>>>>> delattr(person,)
>>>,line 1,
>>> >>>,,,,
r___clear_type_cache_current_frames_debugmallocstats_getframe
>>> divmod(15,35,0)
>>> d=[,,>>> i,j 12 c
>>> a=
>>> wd
code=input(>>>(
>>> res=filter( x:x%2==0,range(10>>> i 2
4
6
8
>>> float(1.0
>>> float(11.0
>>> s=.format(,>>> wd,job IT
>>> ==22>>> getattr(test,22
set(可变集合)与frozenset(不可变集合)的区别:set无序排序且不重复,是可变的,有add(),remove()等方法。既然是可变的,所以它不存在哈希值。基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合),intersection(交集),difference(差集)和sysmmetric difference(对称差集)等数学运算.?sets 支持 x in set,len(set),和 for x in set。作为一个无序的集合,sets不记录元素位置或者插入点。因此,sets不支持 indexing,或其它类序列的操作。frozenset是冻结的集合,它是不可变的,存在哈希值,好处是它可以作为字典的key,也可以作为其它集合的元素。缺点是一旦创建便不能更改,没有add,remove方法。 >>> a=frozenset(>>>,,>>>
>>>: None,: None,: frozenset({,}),,:
>>> ==22>>> hasattr(people,>>> hasattr(people,
>>> >>>NAME
os - OS routines <span style="color: #0000ff;">for NT <span style="color: #0000ff;">or Posix depending on what system we<span style="color: #800000;">'<span style="color: #800000;">re on. <span style="color: #000000;"> DESCRIPTION
>>> hex(16
>>> hex(18
>>>
>>> a=1
>>> id(11602879952,1602879952)
>>> int(,base=1614
>>> int(,base=1610
>>> int(,base=1617
>>> int(,base=23
>>> isinstance([1,3
<div class="cnblogs_code"> >>> a=[1,4>>> b=>>>
<div class="cnblogs_code"> >>> len(3
>>> len([1,44
>>> =>>>: >>>: < >,: < (built-)>,:
>>> b=map( x:x*2,range(5>>> i 2
4
6
8
>>> max([1,4,5,6],key= x:x>14
>>> max([1,66
>>> max([1,key= x:x>7)
1
v = memoryview(b(v[1<span style="color: #0000ff;">import<span style="color: #000000;"> struct
buf = struct.pack(<span style="color: #800000;">"<span style="color: #800000;">i<span style="color: #800000;">"12,list(range(12<span style="color: #000000;">))) x =<span style="color: #000000;"> memoryview(buf) y = x.cast(<span style="color: #800000;">'<span style="color: #800000;">i<span style="color: #800000;">',shape=[2,3<span style="color: #000000;">]) <span style="color: #0000ff;">print<span style="color: #000000;">(y.tolist()) 结果输出如下: 98 97<span style="color: #000000;"> [[[0,1,2],[3,5]],[[6,7,8],[9,10,11]]]
>>> min([1,31
>>> a=iter([1,4>>>1
>>>2
>>> oct(16
>>> oct(9
>>>
>>> ord(97
>>> ord(104
>>> pow(2,38
>>> pow(2,53
>>> i range(1,51
2
3
4
>>> a=reversed([1,4>>> i 4
3
2
1
>>> round(6.67
>>> round(5.425
>>> set(,,}
>>> =>>> a=>>> setattr(a,,22>>>22
<div class="cnblogs_code"> >>> sorted([2,1,8,71,8>>> sorted([,,,,,,,,]
>>> sum([1,410
>>> type(1< >
>>> type(< >
>>> a=[1,3>>> b=[,>>> c=[,,>>> d=>>> i 1,2,3,>>> d=dict(zip(a,b))
>>>1: ,2: ,3: >>> d=zip(a,b,c)
>>> i 1,2,3,,)
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |