python學習 34 內建函式的補充

2022-09-02 06:42:10 字數 769 閱讀 4501

1.ord()    與chr()相反

2.pow()

print(pow(3,3))  #

相當於3**3

print(pow(3,3,2)) #

相當於3*3%2

執行結果:

27

1process finished with exit code 0

3.reversed()  顛倒順序

4.round() 四捨五入

5.slice()  

a = '

hello

's1 = slice(3,5)

s2 = slice(1,4,2) #

2步長print

(a[s1])

print(a[s2])

執行結果:

lo

elprocess finished with exit code 0

6.sorted()  比較之後排序

people =[,,

]print(sorted(people,key=lambda dic:dic['

age']))

執行結果:

[, , ]

process finished with exit code 0

7.sum()求和

8._import_()     可以匯入字串型別的模組。# import 呼叫.py格式的模組

Python內建函式 34 map

英文文件 map function,iterable,function to every item of iterable,yielding the results.if additional iterable arguments are passed,itertools.starmap 使用指定的...

學習python的內建函式

在python中有很多內建函式,當然隨著學習的深入,你也可以學會建立對自己有用的函式。簡單的理解下函式的概念,就是你編寫了一些語句,為了方便使用這些語句,把這些語句組合在一起,給它起乙個名字。使用的時候只要呼叫這個名字,就可以實現語句組的功能了。bool intfloat complex 複數 co...

Python學習 內建函式

迭代器.next next 迭代器 迭代器 iter 可迭代的 迭代器 可迭代的.iter range 10 range 1 11 print next in dic range 1 11,2 特點 1.1.節省記憶體空間 1.2.逐個取值,乙個迭代器只能取一次 生成器含有yield關鍵字的函式都是...