6內(nèi)置函數(shù)

  • 內(nèi)置函數(shù)
abs() dict() help() min() setattr()
all() dir() hex() next() slice()
any() divmod() id() object() sorted()
ascii() enumerate() input() oct() staticmethod()
bin() eval() int() open() str()
bool() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() _import_()
complex() hasattr() max() round()
delattr() hash() memoryview() set()

-常用內(nèi)置函數(shù)

print()
input()
len()
int()
str()
list()
tuple()
range()
help()

open()
map()
join()
split()

  • 數(shù)學(xué)運算
絕對值
>>> abs(-1)
1

最大值
>>> max([1,2,3])
3

最小值
>>> min([1,2,3])
1

求和
>>> sum([1, 2, 3, 4, 5])
15

四舍五入
>>> round(2.6)
3

長度
>>> len('abc')
3

生成1到9
>>> range(1,10)
range(1, 10)

生成1到9,間隔為2
>>> list(range(1, 10, 2))
[1, 3, 5, 7, 9]

反轉(zhuǎn)序列
>>> list(reversed([1, 2, 3, 4, 5, 6]))
[6, 5, 4, 3, 2, 1]

  • 類型轉(zhuǎn)換
轉(zhuǎn)換為整數(shù)
>>> int('5')
5

轉(zhuǎn)換為浮點數(shù)
>>> float('5')
5.0

轉(zhuǎn)換為字符串
>>> str(5)
'5'

轉(zhuǎn)換列表為元組
>>> tuple([1, 2, 3])
(1, 2, 3)

轉(zhuǎn)換元組為列表
>>> list((1, 2, 3))
[1, 2, 3]

轉(zhuǎn)換數(shù)字為ASCI碼
>>> chr(5)
'\x05'

轉(zhuǎn)換ASCI碼為數(shù)字
>>> ord('A')
65

轉(zhuǎn)換為二進(jìn)制
>>> bin(1024)
'0b10000000000'

轉(zhuǎn)換為八進(jìn)制
>>> oct(1024)
'0o2000'

轉(zhuǎn)換為十六進(jìn)制
>>> hex(1024)
'0x400'

哈希值
>>> hash('Passw0rd')
4702269041947070808
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容