标签:clear col 可迭代对象 存在 浅拷贝 top wds key 指定位置
list:类,列表。
list.append() #对象.方法(... ) 称为:list对象调用append方法。
1 例: 2 li = [1,2,3,‘hello‘] 3 a = li[2] 4 print(a) 5 6 输出; 7 3
1 例: 2 li = [1,2,3,‘hello‘] 3 a = li[1:3] 4 print(a) 5 6 输出: 7 [2,3]
1 例: 2 li = [1,2,3,[‘23‘,‘dfs‘,[‘34‘]],‘hello‘] 3 a = li[3][2][0][1] 4 print(a) 5 6 输出: 7 4
1 例: 2 a = ‘dfsdfsf‘ 3 i = list(a) 4 print(i) 5 6 输出: 7 [‘d‘, ‘f‘, ‘s‘, ‘d‘, ‘f‘, ‘s‘, ‘f‘]
1 例: 2 li = [123,23,34,‘df‘,‘sde‘] 3 a = ‘‘ 4 for i in li: 5 a = a + str(i) 6 print(a) 7 8 输出: 9 1232334dfsde
列表只包含字符串:(可用join进行拼接)
1 例: 2 li = [‘df‘,‘sde‘,‘ewdsd‘] 3 i = ‘‘.join(li) 4 print(i) 5 6 输出: 7 dfsdeewdsd
内置方法:
def append(self,p_object)
1 例: 2 li = [‘df‘,‘sde‘,‘ewdsd‘] 3 li.append(‘32‘) 4 print(li) 5 6 输出: 7 [‘df‘, ‘sde‘, ‘ewdsd‘, ‘32‘]
def clear(self, *args, **kwargs)
1 例: 2 li = [‘df‘,‘sde‘,‘ewdsd‘] 3 li.clear() 4 print(li) 5 6 输出: 7 []
def copy(self, *args, **kwargs)
1 例: 2 li = [‘df‘,‘sde‘,‘ewdsd‘] 3 v = li.copy() 4 print(v) 5 6 输出: 7 [‘df‘, ‘sde‘, ‘ewdsd‘]
def count(self, value)
1 例: 2 li = [11,22,33,44,22,‘ewdsd‘] 3 v = li.count(22) 4 print(v) 5 6 输出: 7 2
def extend(self, iterable)
1 例: 2 li = [11,22,33,44,22,‘ewdsd‘] 3 li.extend([11,23]) 4 print(li) 5 6 输出: 7 [11, 22, 33, 44, 22, ‘ewdsd‘, 11, 23]
def index(self, start=None, stop=None)
1 例: 2 li = [11,22,33,44,22,] 3 v = li.index(22,2,5) 4 print(v) 5 6 输出: 7 4
def insert(self, index, p_object)
1 例: 2 li = [11,22,33,44,22,] 3 li.insert(0,99) 4 print(li) 5 6 输出: 7 [99, 11, 22, 33, 44, 22]
def pop(self, index=None)
1 例: 2 li = [11,22,33,44,22,] 3 v = li.pop(1) 4 print(li,v) 5 6 输出: 7 [11, 33, 44, 22] 22
def remove(self, value)
1 例: 2 li = [11,22,33,44,22,] 3 li.remove(22) 4 print(li) 5 6 输出: 7 [11, 33, 44, 22]
del删除列表: del li[1] del li[2:5]
def reverse(self, *args, **kwargs)
1 例: 2 li = [11,22,33,44,22,] 3 li.reverse() 4 print(li) 5 6 输出: 7 [22, 44, 33, 22, 11]
def sort(self, key=None, reverse=False)
1 例: 2 li = [11,22,33,44,22,] 3 li.sort(reverse=True) 4 print(li) 5 6 输出: 7 [44, 33, 22, 22, 11]
标签:clear col 可迭代对象 存在 浅拷贝 top wds key 指定位置
原文地址:https://www.cnblogs.com/liqiongming/p/10016512.html