内置方法
?
1、abs
abs()?2、all(Iterable)所有元素都為真,返回True
all([-1,0,1])all([-1,-1])
all([])#true
?3、any((Iterable)(一真即真)
any([-1,0,1]) any([-1,-1])any([])#false
?4、ascii(object)
變成字符串
5、bin()把整數轉換成2進制
bin(10)?6、bytearray()變成可以修改的數組
a=bytes("abcde",encoding='utf-8')print(a.capitalize(),a) b=bytearray("abcde",encoding='utf-8')
b[1]=100
print(b[0])
7、callable()判斷是不是可以調用
8、chr(i) 必須輸入數字
chr(97)?9 ?ord(‘’)必須字符返回數字
ord('a')?10、classmethod 類方法
11、compile(底層用于將,,轉成源代碼)
code="1+3*3/2"eval(code)
?
code="for i in range(10):print(i)" py_obj=compile(code,'err.log',"exec")?12、dict() 等同于 {} 生成默認字典
divmod(5,3)?13、eval(express) 字符串遍字典, 有語句的不能用,
eval("1+3/2")eval("{'name':'alex'}")
?14、exec將字符串變成代碼執行。
15、filter 一組數據過濾出想要的數據
匿名函數
print((lambda n:print(n))(5))?
res=filter(lambda n:n>5,range(10)) for i in res:print(i)?
16、map?
res=map(lambda n: n**n,rang(10))#對傳入的值進行處理。 for i in res:print(i)17、reduce
import functools functools.reduce(lambda x,y:x+y,range(10))?18、frozenset(iterable)
a=set([1,4,12,1,14,4,10]) b=frozenset([1,4,12,1,14,4,10])?19、globals()整個程序的全局變量
?20、hash(object)
21、help
22、hex(x)轉成16進制?
23 len
24、locals()
locals不打印globals
globals不打印locals
25、max ?min
26、oct(i)轉8進制
27 power(3,5)
28、repr(object) 用字符串表示對象。
29、reversed(seq)
30、round()
31、切片
d=range(0,20) d[slice(2,5)]?32、sorted
a = {6:2,8:1,1:4,-5:29}print(a)
sorted(a.items())#變成列表 按key排序
sorted(a.items(),key=lambda x:x[1])
?33、sum
34、type(object)
35、vars([object])返回對象的所有屬性名
36、zip 按最少的拼,map可以補None或指定
a=[1,2,3,4,5,6] b=['a','b','c','d','e','f'] for i in zip(a,b):print(i)?37、import?
__import__('decorator')#?
轉載于:https://www.cnblogs.com/LittleSpring/p/9351509.html
總結
- 上一篇: [leetcode] 874. 行走机器
- 下一篇: Fomo3d常见问题