lambda表達式+python內置函數
阿新 • • 發佈:2017-09-20
com strong ges encoding 結果 字節 pan 對象 rep
傳統的定義函數方式如下
def f1(): return 123
lambda表達式定義函數
f2 = lambda : 123
python3的內置函數
1.abs 絕對值
i = abs(-11) print (i)
輸出結果是11
abs = absolute
2,all 循環參數,如果每個元素都為真,則返回為真
r = all([True, True]) print (r)
在python中 0 () [] ‘‘和 None是False(空值都是假的)
r = all(["123"," ", [1,2],""]) print (r)
返回為False
3,any 只要有一個為真 就為True
i = any([None," ","123"]) print (i)
返回為True
4,ascii 自動執行 ascii(對象)去對象的類中,找__reper__,獲取返回值
class Foo: def __repr__(self): return "hello" obj = Foo() r = ascii(obj) print (r)
返回值為hello
5,bin()二進制 oct()八進制 int()十進制 hex()十六進制
6,bool判斷真假:本質上是把一個對象轉換成布爾值
7,bytes(字節)bytesarray(字節列表)
補充字節和字符串之間的轉換
bytes("xxxxx",encoding="uft-8")
8,chr() ord()
c = chr(65)
print (c)
返回值是A
chr找到對應ascii碼中對應的字符(ascii碼是一個字符對應一個字節)
同理 ord(a)
返回97 通過ord把一個字符轉換成數字
lambda表達式+python內置函數