1. 程式人生 > >第三天學習總結

第三天學習總結

turned values 對象 esp 一個 iterable ems sel 排序

#######################list 類 列表########################
li = [1, 2, 343, dfas, [fsad, dfas], True]
# list 是一個集合 能放任何東西進去
# print(li[0:3])
# list 是可以修改的

# 索引法
# li[1]
# a = li[4][0] value = ‘fsad‘

# 切片法
# li[3:5] = [3223,3432]

# 列表中的元素是以,分割 一個一個是整體
# li[1] = ‘fdasdf‘
# print(li)

# in 操作

# for 循環 while循環
tuple # 刪除 # del li[1] list #####轉換 # 字符串轉化為列表 li = list[‘dfsadfasdf‘] #若列表裏只有字符串 ‘‘‘li = [‘dfas‘,‘fdsaf‘] v = "".join(li) print(v) ‘‘‘ #列表裏不只有字符串 可以使用for循環 ‘‘‘ s = "" for itm in li: s = s + str(itm) print(itm) ‘‘‘ # list類中提供的方法 ‘‘‘ l、li.append(self, p_object): # real signature unknown; restored from __doc__ """ L.append(object) -> None -- append object to end """ v = li.append(5) 原值最後追加 v的value 位none li.append([‘‘,‘‘]) 2、清空列表 li.clear() 3、拷貝 count(self, value): # real signature unknown; restored from __doc__ L.count(value) -> integer -- return number of occurrences of value 4、計數 count(self, value): # real signature unknown; restored from __doc__ L.count(value) -> integer -- return number of occurrences of value 5、擴展原列表 參數為可叠代對象:字符串、列表框、元組 註意和append的區別 extend(self, iterable): # real signature unknown; restored from __doc__ L.extend(iterable) -> None -- extend list by appending elements from the iterable li = [112,232,3213,3] li.append([213,3213]) print(li) [112,232,3213,3,[213,3213]] li = [112,232,3213,3] li.extend([213,3213]) print(li) [112,232,3213,3,213,3213] 6、根據索引值獲取位置 index index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ L.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. 7、在指定索引位置插值 insert insert(self, index, p_object): # real signature unknown; restored from __doc__ L.insert(index, object) -- insert object before index 8、刪除索引對應的值 不指定索引默認最後一個值 並獲取刪除值 pop(self, index=None): # real signature unknown; restored from __doc__ L.pop([index]) -> item -- remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. li = [112,232,3213,3] v = li.[1] print(v,li) 232 [112,3213,3] 9、選擇刪除值 remove remove(self, value): # real signature unknown; restored from __doc__ """ L.remove(value) -> None -- remove first occurrence of value. Raises ValueError if the value is not present. """ # pop remove del li[0] del li[1:2] 10、反轉 reverse reverse(self): # real signature unknown; restored from __doc__ """ L.reverse() -- reverse *IN PLACE* """ 11、排序 sort sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__ """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """ reverse = False 從小到大排序 #list 有序且可以被修改
‘‘‘ dict ###########################元組tuple######################### ‘‘‘ 元組一旦被創建 一級元素不可修改、不能被增加和刪除 嵌套的列表框可以修改 tuple 是有序的 可以進行索引 可以進行切片 可以進行for 循環 while循環 最好創建的時候加一個小逗號 tup = (fasdf,fdsfdfd,) tu = (dfas,erw,rewr,[(33,44)],4234) #獲取33 v = tu[3][0][0] print(v) 33 b = tu[3][0] =234 print(b) tu = (dfas,erw,rewr,[234],4234) #############list方法 1、計數 count count(self, value): # real signature unknown; restored from __doc__ """ T.count(value) -> integer -- return number of occurrences of value """ return 0 2、找尋 index index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ """ T.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. """
‘‘‘ ############################字典 ############# ‘‘‘ info = {"k1":v1,"k2":"v2"} #"k1":"v1" 鍵值對 key:value value 可以為任意值 key : 數字、字符串、元組 都可以 列表不可以 哈希表 #索引使用key值 自己申明的 #無序狀態無法切片 #刪除 del info[key] # for 循環 默認只循環key for item in info.keys for item in info.values for item in info .items 鍵值對 ####or for item in info.keys print(item,info[item]) True 1 False 0 作為key 可能與1 重復 ‘‘‘ ####################dict 常用方法 ‘‘‘ 1、dict() 2、clear(self): # real signature unknown; restored from __doc__ """ D.clear() -> None. Remove all items from D. """ pass 3、 copy(self): # real signature unknown; restored from __doc__ """ D.copy() -> a shallow copy of D """ pass 4、@staticmethod # known case直接寫個類名就可以了 靜態方法 fromkeys(*args, **kwargs): # real signature unknown 第一個參數為key 第二個參數為value """ Returns a new dict with keys from iterable and values equal to value. """ 創建字典,指定統一的值 pass ####5、get(self, k, d=None): # real signature unknown; restored from __doc__ """ D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. """ 根據key取value值 key不存在時返回d值 d默認值為none 6、pop(self, k, d=None): # real signature unknown; restored from __doc__ """ D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised 刪除值 若key值不存在返回d 7、popitem(self): # real signature unknown; restored from __doc__ """ D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty. """隨機刪除一對鍵值對 8、setdefault(self, k, d=None): # real signature unknown; restored from __doc__ """ D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """ 設置值:如果已經存在的key 不設置 獲取原對應的value 若不存在 設置該value 9、update(self, E=None, **F): # known special case of dict.update """ D.update([E, ]**F) -> None. Update D from dict/iterable E and F. If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] """ 已經存在 覆蓋掉 不存在 賦值 dic.update(k1=123,k3=234,k5="dfas") 自動轉換成字典 ‘‘‘ ###############################大整理##################### ‘‘‘ #數字 int #字符串 replace find join strip startwith endwith upper lower format 特殊的 v = template.format(**{name:‘fdsa‘,age:‘fdasf‘}) #列表 append extend insert 索引、切片、循環 #元組 忽略 #字典 get update keys values items for 索引 #布爾值 0 1 bool() 為假的:none () 0 ‘‘ [] {} ‘‘‘

第三天學習總結