Python开发(基础):列表List

简介:
  • List 内置函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python
# -*- coding:utf-8 -*-
 
# class list(object):
#     """
#     list() -> new empty list
#     list(iterable) -> new list initialized from iterable's items
#     """
#
#     def append(self, p_object):  # real signature unknown; restored from __doc__
#         在list尾部追加
#         """ L.append(object) -- append object to end """
#         pass
li  =  [ 'alex' , 'tom' , 'aric' , 'tony' , 'alex' ]
li.append( 'jason' )
print  li
#['alex', 'tom', 'aric', 'tony', 'alex', 'jason']
#     def count(self, value):  # real signature unknown; restored from __doc__
#         返回list中某个值出现的次数
#         """ L.count(value) -> integer -- return number of occurrences of value """
#         return 0
print  li.count( 'alex' )
#     def extend(self, iterable):  # real signature unknown; restored from __doc__
#         将一个可迭代的对象追加到list尾部
#         """ L.extend(iterable) -- extend list by appending elements from the iterable """
#         pass
li.extend(( 'steven' , 'whales' ))
print  li
#['alex', 'tom', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales']
li.extend( 'Tomcat' )
#['alex', 'tom', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a', 't']
print  li
#     def index(self, value, start=None, stop=None):  # real signature unknown; restored from __doc__
#         返回list中某个值第一次出现的索引位置
#         """
#         L.index(value, [start, [stop]]) -> integer -- return first index of value.
#         Raises ValueError if the value is not present.
#         """
#         return 0
print  li.index( 'alex' )
#0
#   def insert(self, index, p_object):  # real signature unknown; restored from __doc__
#         在list的某个索引位置插入一个值
#         """ L.insert(index, object) -- insert object before index """
#         pass
li.insert( 2 , 'Andy' )
print  li
#['alex', 'tom', 'Andy', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a', 't']
#     def pop(self, index=None):  # real signature unknown; restored from __doc__
#         """
#         取出list中最后一个索引位置上的值,并删除
#         L.pop([index]) -> item -- remove and return item at index (default last).
#         Raises IndexError if list is empty or index is out of range.
#         """
#         pass
last_value  =  li.pop()
print  last_value;
print  li
#t
#['alex', 'tom', 'Andy', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a']
#     def remove(self, value):  # real signature unknown; restored from __doc__
#         """
#         删除list中某个值,从左往右,只删除一次,如果存在多个相同的值需要全部删除,需执行多次
#         L.remove(value) -- remove first occurrence of value.
#         Raises ValueError if the value is not present.
#         """
#         pass
li.remove( 'alex' )
print  li
#['tom', 'Andy', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a']
#     def reverse(self):  # real signature unknown; restored from __doc__
#         反转
#         """ L.reverse() -- reverse *IN PLACE* """
#         pass
li.reverse()
print  li
#['a', 'c', 'm', 'o', 'T', 'whales', 'steven', 'jason', 'alex', 'tony', 'aric', 'Andy', 'tom']
#     def sort(self, cmp=None, key=None, reverse=False):  # real signature unknown; restored from __doc__
#         """
#         排序
#         L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
#         cmp(x, y) -> -1, 0, 1
#         """
#         pass
li.sort()
print  li
#['Andy', 'T', 'a', 'alex', 'aric', 'c', 'jason', 'm', 'o', 'steven', 'tom', 'tony', 'whales']
#     def __add__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__add__(y) <==> x+y """
#         pass
#
#     def __contains__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__contains__(y) <==> y in x """
#         pass
#
#     def __delitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__delitem__(y) <==> del x[y] """
#         pass
#
#     def __delslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__delslice__(i, j) <==> del x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __eq__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__eq__(y) <==> x==y """
#         pass
#
#     def __getattribute__(self, name):  # real signature unknown; restored from __doc__
#         """ x.__getattribute__('name') <==> x.name """
#         pass
#
#     def __getitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__getitem__(y) <==> x[y] """
#         pass
#
#     def __getslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__getslice__(i, j) <==> x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __ge__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ge__(y) <==> x>=y """
#         pass
#
#     def __gt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__gt__(y) <==> x>y """
#         pass
#
#     def __iadd__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__iadd__(y) <==> x+=y """
#         pass
#
#     def __imul__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__imul__(y) <==> x*=y """
#         pass
#
#     def __init__(self, seq=()):  # known special case of list.__init__
#         """
#         list() -> new empty list
#         list(iterable) -> new list initialized from iterable's items
#         # (copied from class doc)
#         """
#         pass
#
#     def __iter__(self):  # real signature unknown; restored from __doc__
#         """ x.__iter__() <==> iter(x) """
#         pass
#
#     def __len__(self):  # real signature unknown; restored from __doc__
#         """ x.__len__() <==> len(x) """
#         pass
#
#     def __le__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__le__(y) <==> x<=y """
#         pass
#
#     def __lt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__lt__(y) <==> x<y """
#         pass
#
#     def __mul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__mul__(n) <==> x*n """
#         pass
#
#     @staticmethod  # known case of __new__
#     def __new__(S, *more):  # real signature unknown; restored from __doc__
#         """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
#         pass
#
#     def __ne__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ne__(y) <==> x!=y """
#         pass
#
#     def __repr__(self):  # real signature unknown; restored from __doc__
#         """ x.__repr__() <==> repr(x) """
#         pass
#
#     def __reversed__(self):  # real signature unknown; restored from __doc__
#         """ L.__reversed__() -- return a reverse iterator over the list """
#         pass
#
#     def __rmul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__rmul__(n) <==> n*x """
#         pass
#
#     def __setitem__(self, i, y):  # real signature unknown; restored from __doc__
#         """ x.__setitem__(i, y) <==> x[i]=y """
#         pass
#
#     def __setslice__(self, i, j, y):  # real signature unknown; restored from __doc__
#         """
#         x.__setslice__(i, j, y) <==> x[i:j]=y
#
#                    Use  of negative indices is not supported.
#         """
#         pass
#
#     def __sizeof__(self):  # real signature unknown; restored from __doc__
#         """ L.__sizeof__() -- size of L in memory, in bytes """
#         pass
#
#     __hash__ = None

  • List 内置函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python
# -*- coding:utf-8 -*-
 
# class list(object):
#     """
#     list() -> new empty list
#     list(iterable) -> new list initialized from iterable's items
#     """
#
#     def append(self, p_object):  # real signature unknown; restored from __doc__
#         在list尾部追加
#         """ L.append(object) -- append object to end """
#         pass
li  =  [ 'alex' , 'tom' , 'aric' , 'tony' , 'alex' ]
li.append( 'jason' )
print  li
#['alex', 'tom', 'aric', 'tony', 'alex', 'jason']
#     def count(self, value):  # real signature unknown; restored from __doc__
#         返回list中某个值出现的次数
#         """ L.count(value) -> integer -- return number of occurrences of value """
#         return 0
print  li.count( 'alex' )
#     def extend(self, iterable):  # real signature unknown; restored from __doc__
#         将一个可迭代的对象追加到list尾部
#         """ L.extend(iterable) -- extend list by appending elements from the iterable """
#         pass
li.extend(( 'steven' , 'whales' ))
print  li
#['alex', 'tom', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales']
li.extend( 'Tomcat' )
#['alex', 'tom', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a', 't']
print  li
#     def index(self, value, start=None, stop=None):  # real signature unknown; restored from __doc__
#         返回list中某个值第一次出现的索引位置
#         """
#         L.index(value, [start, [stop]]) -> integer -- return first index of value.
#         Raises ValueError if the value is not present.
#         """
#         return 0
print  li.index( 'alex' )
#0
#   def insert(self, index, p_object):  # real signature unknown; restored from __doc__
#         在list的某个索引位置插入一个值
#         """ L.insert(index, object) -- insert object before index """
#         pass
li.insert( 2 , 'Andy' )
print  li
#['alex', 'tom', 'Andy', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a', 't']
#     def pop(self, index=None):  # real signature unknown; restored from __doc__
#         """
#         取出list中最后一个索引位置上的值,并删除
#         L.pop([index]) -> item -- remove and return item at index (default last).
#         Raises IndexError if list is empty or index is out of range.
#         """
#         pass
last_value  =  li.pop()
print  last_value;
print  li
#t
#['alex', 'tom', 'Andy', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a']
#     def remove(self, value):  # real signature unknown; restored from __doc__
#         """
#         删除list中某个值,从左往右,只删除一次,如果存在多个相同的值需要全部删除,需执行多次
#         L.remove(value) -- remove first occurrence of value.
#         Raises ValueError if the value is not present.
#         """
#         pass
li.remove( 'alex' )
print  li
#['tom', 'Andy', 'aric', 'tony', 'alex', 'jason', 'steven', 'whales', 'T', 'o', 'm', 'c', 'a']
#     def reverse(self):  # real signature unknown; restored from __doc__
#         反转
#         """ L.reverse() -- reverse *IN PLACE* """
#         pass
li.reverse()
print  li
#['a', 'c', 'm', 'o', 'T', 'whales', 'steven', 'jason', 'alex', 'tony', 'aric', 'Andy', 'tom']
#     def sort(self, cmp=None, key=None, reverse=False):  # real signature unknown; restored from __doc__
#         """
#         排序
#         L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
#         cmp(x, y) -> -1, 0, 1
#         """
#         pass
li.sort()
print  li
#['Andy', 'T', 'a', 'alex', 'aric', 'c', 'jason', 'm', 'o', 'steven', 'tom', 'tony', 'whales']
#     def __add__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__add__(y) <==> x+y """
#         pass
#
#     def __contains__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__contains__(y) <==> y in x """
#         pass
#
#     def __delitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__delitem__(y) <==> del x[y] """
#         pass
#
#     def __delslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__delslice__(i, j) <==> del x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __eq__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__eq__(y) <==> x==y """
#         pass
#
#     def __getattribute__(self, name):  # real signature unknown; restored from __doc__
#         """ x.__getattribute__('name') <==> x.name """
#         pass
#
#     def __getitem__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__getitem__(y) <==> x[y] """
#         pass
#
#     def __getslice__(self, i, j):  # real signature unknown; restored from __doc__
#         """
#         x.__getslice__(i, j) <==> x[i:j]
#
#                    Use of negative indices is not supported.
#         """
#         pass
#
#     def __ge__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ge__(y) <==> x>=y """
#         pass
#
#     def __gt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__gt__(y) <==> x>y """
#         pass
#
#     def __iadd__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__iadd__(y) <==> x+=y """
#         pass
#
#     def __imul__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__imul__(y) <==> x*=y """
#         pass
#
#     def __init__(self, seq=()):  # known special case of list.__init__
#         """
#         list() -> new empty list
#         list(iterable) -> new list initialized from iterable's items
#         # (copied from class doc)
#         """
#         pass
#
#     def __iter__(self):  # real signature unknown; restored from __doc__
#         """ x.__iter__() <==> iter(x) """
#         pass
#
#     def __len__(self):  # real signature unknown; restored from __doc__
#         """ x.__len__() <==> len(x) """
#         pass
#
#     def __le__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__le__(y) <==> x<=y """
#         pass
#
#     def __lt__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__lt__(y) <==> x<y """
#         pass
#
#     def __mul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__mul__(n) <==> x*n """
#         pass
#
#     @staticmethod  # known case of __new__
#     def __new__(S, *more):  # real signature unknown; restored from __doc__
#         """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
#         pass
#
#     def __ne__(self, y):  # real signature unknown; restored from __doc__
#         """ x.__ne__(y) <==> x!=y """
#         pass
#
#     def __repr__(self):  # real signature unknown; restored from __doc__
#         """ x.__repr__() <==> repr(x) """
#         pass
#
#     def __reversed__(self):  # real signature unknown; restored from __doc__
#         """ L.__reversed__() -- return a reverse iterator over the list """
#         pass
#
#     def __rmul__(self, n):  # real signature unknown; restored from __doc__
#         """ x.__rmul__(n) <==> n*x """
#         pass
#
#     def __setitem__(self, i, y):  # real signature unknown; restored from __doc__
#         """ x.__setitem__(i, y) <==> x[i]=y """
#         pass
#
#     def __setslice__(self, i, j, y):  # real signature unknown; restored from __doc__
#         """
#         x.__setslice__(i, j, y) <==> x[i:j]=y
#
#                    Use  of negative indices is not supported.
#         """
#         pass
#
#     def __sizeof__(self):  # real signature unknown; restored from __doc__
#         """ L.__sizeof__() -- size of L in memory, in bytes """
#         pass
#
#     __hash__ = None

本文转自  wbb827  51CTO博客,原文链接:http://blog.51cto.com/wbb827/1933505
相关文章
|
4月前
|
存储 JavaScript Java
(Python基础)新时代语言!一起学习Python吧!(四):dict字典和set类型;切片类型、列表生成式;map和reduce迭代器;filter过滤函数、sorted排序函数;lambda函数
dict字典 Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度。 我们可以通过声明JS对象一样的方式声明dict
343 1
|
4月前
|
开发者 Python
Python列表推导式:优雅与效率的完美结合
Python列表推导式:优雅与效率的完美结合
482 116
|
4月前
|
大数据 开发者 Python
Python列表推导式:简洁与高效的艺术
Python列表推导式:简洁与高效的艺术
431 109
|
4月前
|
Python
Python列表推导式:简洁与高效的艺术
Python列表推导式:简洁与高效的艺术
500 119
|
4月前
|
Python
Python列表推导式:优雅与效率的艺术
Python列表推导式:优雅与效率的艺术
351 99
|
4月前
|
数据处理 Python
解锁Python列表推导式:优雅与效率的完美融合
解锁Python列表推导式:优雅与效率的完美融合
334 99
|
4月前
|
Python
Python列表推导式:简洁与高效的艺术
Python列表推导式:简洁与高效的艺术
|
4月前
|
索引 Python
Python 列表切片赋值教程:掌握 “移花接木” 式列表修改技巧
本文通过生动的“嫁接”比喻,讲解Python列表切片赋值操作。切片可修改原列表内容,实现头部、尾部或中间元素替换,支持不等长赋值,灵活实现列表结构更新。
229 1
|
4月前
|
存储 Java 索引
(Python基础)新时代语言!一起学习Python吧!(二):字符编码由来;Python字符串、字符串格式化;list集合和tuple元组区别
字符编码 我们要清楚,计算机最开始的表达都是由二进制而来 我们要想通过二进制来表示我们熟知的字符看看以下的变化 例如: 1 的二进制编码为 0000 0001 我们通过A这个字符,让其在计算机内部存储(现如今,A 字符在地址通常表示为65) 现在拿A举例: 在计算机内部 A字符,它本身表示为 65这个数,在计算机底层会转为二进制码 也意味着A字符在底层表示为 1000001 通过这样的字符表示进行转换,逐步发展为拥有127个字符的编码存储到计算机中,这个编码表也被称为ASCII编码。 但随时代变迁,ASCII编码逐渐暴露短板,全球有上百种语言,光是ASCII编码并不能够满足需求
238 4
|
4月前
|
索引 Python
098-python列表_切片_slice_开始_结束
本文介绍了Python中列表的切片(slice)操作,通过“前闭后开”原则截取列表片段,支持正负索引、省略端点等用法,并结合生活实例(如切面包、直播切片)帮助理解。切片不改变原列表,返回新列表。
341 4

推荐镜像

更多