整理遇到的python BIF函数,按照字母顺序排序,长期更新,如发现问题,欢迎评论留言,谢谢。
>>> case.append("增加一个")
>>> case
[1, 2, '文', [3, 4, 5], 'asd', '增加一个']
close():关闭文件
enumerate():创建成对数据的一个编号列表,从0开始
extend():在列表末尾增加一个数据集合
>>> case.extend([999,666,'999'])
>>> case
[1, '文', [3, 4, 5], 'asd', 999, 666, '999']
>>> case="Man:Yes:NO"
>>> case.find(":")
3
>>> case[0]
'M'
>>> case.find(",")
-1
>>> case.insert(0,"插入")
>>> case
['插入', 1, '文', [3, 4, 5], 'asd', 666, '999']
>>> name=[1,2,4,'文']
>>> isinstance(name,list)
True
>>> locals()
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class
'_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module
'builtins' (built-in)>}
>>> case
[1, 2, '文', [3, 4, 5], 'asd']
>>> case.pop(1)
2
>>> case
[1, '文', [3, 4, 5], 'asd']
>>> for num in range(4):
print (num)
0
1
2
3
>>> case.remove(999)
>>> case
[1, '文', [3, 4, 5], 'asd', 666, '999']
>>> case="Man:Yes"
>>> (role,line)=case.split(":")
>>> role
'Man'
>>> line
'Yes'
>>> case="Man:Yes:NO"
>>> (role,line)=case.split(":")
Traceback (most recent call last):
File "" , line 1, in <module>
(role,line)=case.split(":")
ValueError: too many values to unpack (expected 2)
>>> (role,line)=case.split(":",1)
>>> role
'Man'
>>> line
'Yes:NO'
>>> case=[3,5,1,6]
>>> case.sort()
>>> case
[1, 3, 5, 6]
>>> case=[3,5,1,6]
>>> sorted(case)
[1, 3, 5, 6]
>>> case
[3, 5, 1, 6]
>>> case = ' I am handsome~'
>>> sorted(case)
[' ', ' ', ' ', ' ', 'I', 'a', 'a', 'd', 'e', 'h', 'm', 'm', 'n', 'o', 's', '~']
>>> case = ' I am handsome~'
>>> case.strip()
'I am handsome~'
>>> case
' I am handsome~'