列表详解
1.append
def append(self, *args, **kwargs): # real signature unknown
""" Append object to the end of the list. """
pass
翻译:在列表的最后加追加对象
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.append('名字') 4 print(test)View Code
2.clear
def clear(self, *args, **kwargs): # real signature unknown
""" Remove all items from list. """
pass
翻译:全部删除
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.clear() 4 print(test)View Code
3.copy
def copy(self, *args, **kwargs): # real signature unknown
""" Return a shallow copy of the list. """
pass
翻译:复制一份列表影子副本,即第一层会复制,第二层只存了对象地址
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 x=test.copy() 4 print(test) 5 print(x) 6 test[1]=[1,2,3] #将test里面第2个参数改为列表 7 print(test) #test已经改了 8 print(x) #x没有改 9 x=test.copy() #再复制一份改了之后的test 10 test[1][1]=3 #将test里面第2个参数的第二个参数改为3(即第2层) 11 print(test) #test改了 12 print(x) #x也改了View Code
4.count
def count(self, *args, **kwargs): # real signature unknown
""" Return number of occurrences of value. """
pass
翻译:统计值出现的次数
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 print(test.count(1))View Code
5.extend
def extend(self, *args, **kwargs): # real signature unknown
""" Extend list by appending elements from the iterable. """
pass
翻译:追加可迭代元素类扩展列表,并且是以多个元素的形式如可扩展列表为[1,2,3],则追加值为1,2,3个元素
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.extend([1,2,3]) 4 print(test)View Code
6.index
def index(self, *args, **kwargs): # real signature unknown
"""
Return first index of value.
Raises ValueError if the value is not present.
"""
pass
翻译:返回值的第一个位置,如果不存在则抛出异常ValueError
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.append('名字') 4 print(test.index('名字'))View Code
7.insert
def insert(self, *args, **kwargs): # real signature unknown
""" Insert object before index. """
pass
翻译:在索引前插入对象
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.append('名字') 4 test.insert(1,'可口可乐') 5 print(test)View Code
8.pop
def pop(self, *args, **kwargs): # real signature unknown
"""
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
"""
pass
翻译:默认移除对象的最后一个值
如果列表为空或者索引超出范围,则抛出IndexError
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.append('名字') 4 test.insert(1,'可口可乐') 5 print(test) 6 test.pop() 7 print(test) 8 test.pop(1) 9 print(test)View Code
9.remove
def remove(self, *args, **kwargs): # real signature unknown
"""
Remove first occurrence of value.
Raises ValueError if the value is not present.
"""
pass
翻译:移除第一个出现的值
如果值不存在在抛出ValueError
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.append('名字') 4 test.remove('名字') 5 print(test)View Code
10.reverse
def reverse(self, *args, **kwargs): # real signature unknown
""" Reverse *IN PLACE*. """
pass
翻译:倒置
1 #!/usr/bin/python 2 test =[1,2,3,4,5,6,7,8,'A','B','C'] 3 test.append('名字') 4 test.reverse() 5 print(test)View Code
11.sort
def sort(self, *args, **kwargs): # real signature unknown
"""
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them,
ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.
"""
pass
翻译:返回列表按升序排列
排序是原位的(列表本身被修改)和稳定的(保持2个相等元素的顺序)
如果是一个函数,那么一档应用它到每个列表并排序,升序或降序根据他函数的值
转置表示被用来降序排列
1 #!/usr/bin/python 2 test =['1','2','3','4','5','6','7','8','A','B','C'] 3 test.append('名字') 4 test.sort()# '<' not supported between instances of 'int' and 'str' 5 print(test) 6 test.sort(reverse=True)# '<' not supported between instances of 'int' and 'str' 7 print(test)View Code
标签:bin,python,pass,列表,print,kwargs,test From: https://www.cnblogs.com/Little-Girl/p/17975215