天天看點

複習 Python 匿名函數 内建函數

lamba

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

補充:

複習 Python 匿名函數 内建函數

如圖:

複習 Python 匿名函數 内建函數

舉例:

複習 Python 匿名函數 内建函數

上例中的reduce用法:

複習 Python 匿名函數 内建函數

内建函數

複習 Python 匿名函數 内建函數

如圖,有137的函數、類等等

複習 Python 匿名函數 内建函數

類的單詞首字母是大寫的

檢視函數或者類的方法:

複習 Python 匿名函數 内建函數

常用的内建函數:

1.傳回數字的絕對值

檢視内置函數方法:

複習 Python 匿名函數 内建函數

是以:

複習 Python 匿名函數 内建函數

2.取清單最大最小值

複習 Python 匿名函數 内建函數

取大小值内建函數方法:

複習 Python 匿名函數 内建函數

比較多個參數:

複習 Python 匿名函數 内建函數

比較數字大小:

複習 Python 匿名函數 内建函數

常用内建函數

len() 函數

複習 Python 匿名函數 内建函數

字元串、元組、清單、字典都可以。一下為字典例子:

複習 Python 匿名函數 内建函數

divmod() 内建函數:

複習 Python 匿名函數 内建函數

由說明可以看出,這個函數的作用是傳回兩個數字的商和餘數。

複習 Python 匿名函數 内建函數

pow()内建函數:

複習 Python 匿名函數 内建函數

當兩個參數的時候,等于x的y次方,當三個參數的時候,等于x的y次方再跟z取餘

複習 Python 匿名函數 内建函數

round() 内建函數:

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

callable()内建函數:

複習 Python 匿名函數 内建函數

判斷這個對象是不是可調用的

複習 Python 匿名函數 内建函數

type() 内建函數:

複習 Python 匿名函數 内建函數

isinstance() 内建函數:

複習 Python 匿名函數 内建函數

傳回布爾值

之前定義過 l 和 s 的函數:

複習 Python 匿名函數 内建函數

和type的不用隻處:

判斷類的時候,用isinstance能更好的判斷出來。

cmp() 内建函數:

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

比較字元串:

複習 Python 匿名函數 内建函數

是按照字元來比較的,不是按照長度比較的。

range() 和 xrange() 這兩個之前已經見過。

類型轉換,内置函數:

int()

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

long()

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

float()

複習 Python 匿名函數 内建函數

complex()

轉變成一個複數

複習 Python 匿名函數 内建函數

str()

複習 Python 匿名函數 内建函數

list()

複習 Python 匿名函數 内建函數

type()

複習 Python 匿名函數 内建函數

hex()

傳回16進制的字元串

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

eval()

将16進制還原成10進制

複習 Python 匿名函數 内建函數

oct() 把10進制轉換成8進制

自己研究一下

chr()内建函數

複習 Python 匿名函數 内建函數

傳回的是對應的ascII碼的字元。

複習 Python 匿名函數 内建函數

ord() 内建函數

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

關于字元串處理的内建函數(即,方法):

str.capitalize()

複習 Python 匿名函數 内建函數

檢視方法

複習 Python 匿名函數 内建函數

方法說明:

複習 Python 匿名函數 内建函數

傳回一個字元串,字元串的首字母被大寫。

複習 Python 匿名函數 内建函數

str.replace()

複習 Python 匿名函數 内建函數

說明:替換字元串

複習 Python 匿名函數 内建函數

str.split()  

把字元串切成清單

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

str.join()

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

string 子產品

import sting   導入子產品

很多方法

複習 Python 匿名函數 内建函數

列印所有小寫字母

複習 Python 匿名函數 内建函數

列印所有大寫字母

複習 Python 匿名函數 内建函數

把字元串第一個字母變成大寫

複習 Python 匿名函數 内建函數

替換字元串

複習 Python 匿名函數 内建函數

序列處理函數:

filter()

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

定義函數名:

複習 Python 匿名函數 内建函數

通過函數處理後:

複習 Python 匿名函數 内建函數

zip()

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

當第三個清單的長度與前兩個不同的時候,按最短的取。

複習 Python 匿名函數 内建函數

map()

複習 Python 匿名函數 内建函數

兩個清單使用:

複習 Python 匿名函數 内建函數

reduce()

複習 Python 匿名函數 内建函數
複習 Python 匿名函數 内建函數

fileter   +  匿名函數

複習 Python 匿名函數 内建函數

map + 匿名函數

複習 Python 匿名函數 内建函數

reduce + 匿名函數

複習 Python 匿名函數 内建函數