Python (List)
Python - 01
Python6
Python
Python
list1 = ['physics', 'chemistry', 1997, 2000]
list2 = [1, 2, 3, 4, 5 ]
list3 = ["a", "b", "c", "d"]
0
(Python 2.0+)
#!/usr/bin/python
list1 = ['physics', 'chemistry', 1997, 2000]
list2 = [1, 2, 3, 4, 5, 6, 7 ]
print "list1[0]: ", list1[0]
print "list2[1:5]: ", list2[1:5]
list1[0]: physics list2[1:5]: [2, 3, 4, 5]
append()
(Python 2.0+)
#!/usr/bin/python
# -*- coding: UTF-8 -*-
list = [] ##
list.append('Google') ## append()
list.append('Runoob')
print list
append()
['Google', 'Runoob']
del
(Python 2.0+)
#!/usr/bin/python
list1 = ['physics', 'chemistry', 1997, 2000]
print list1
del list1[2]
print "After deleting value at index 2 : "
print list1
['physics', 'chemistry', 1997, 2000] After deleting value at index 2 : ['physics', 'chemistry', 2000]
remove()
Python
+ * + *
| Python | ||
|---|---|---|
| len([1, 2, 3]) | 3 | |
| [1, 2, 3] + [4, 5, 6] | [1, 2, 3, 4, 5, 6] | |
| ['Hi!'] * 4 | ['Hi!', 'Hi!', 'Hi!', 'Hi!'] | |
| 3 in [1, 2, 3] | True | |
| for x in [1, 2, 3]: print x, | 1 2 3 |
Python
Python
>>>L = ['Google', 'Runoob', 'Taobao']
>>> L[2]
'Taobao'
>>> L[-2]
'Runoob'
>>> L[1:]
['Runoob', 'Taobao']
>>>
| Python | ||
|---|---|---|
| L[2] | 'Taobao' | |
| L[-2] | 'Runoob' | |
| L[1:] | ['Runoob', 'Taobao'] |
Python&
Python:
| 1 | cmp(list1, list2) |
| 2 | len(list) |
| 3 | max(list) |
| 4 | min(list) |
| 5 | list(seq) |
Python:
| 1 | list.append(obj) |
| 2 | list.count(obj) |
| 3 | list.extend(seq) |
| 4 | list.index(obj) |
| 5 | list.insert(index, obj) |
| 6 | list.pop([index=-1]) |
| 7 | list.remove(obj) |
| 8 | list.reverse() |
| 9 | list.sort(cmp=None, key=None, reverse=False) |
tianqixin
429***[email protected]
python cols rows
tianqixin
429***[email protected]
python list
791***[email protected]
#!/usr/bin/python # -*- coding: UTF-8 -*- list01 = ['runoob', 786, 2.23, 'john', 70.2] list02 = [123, 'john'] print list01 print list02 # print list01[0] print list01[-1] print list01[0:3] # print list01 * 2 # print list01 + list02 # print len(list01) # del list02[0] print list02 # print 'john' in list02 # True # for i in list01: print i # print cmp(list01, list02) # / print max([0, 1, 2, 3, 4]) print min([0, 1]) # aTuple = (1,2,3,4) list03 = list(aTuple) print list03 # list03.append(5) print list03 # list03.extend(list01) print list03 # print list03.count(1) # print list03.index('john') # list03.insert(0, 'hello') print list03 # print list03.pop(0) print list03 # list03.remove(1) print list03 # list03.reverse() print list03 # list03.sort() print list03python list
791***[email protected]
740***[email protected]
740***[email protected]
155***[email protected]
num_list = [[1,2,3],[4,5,6]] for i in num_list: for j in i: print(j)155***[email protected]
xsx***[email protected]
[:-1] :
xsx***[email protected]
zha***[email protected]
a a[:]
id()
False
a[:] a a[:] a a a append()
zha***[email protected]
145***[email protected]
145***[email protected]
144***[email protected]
remove del
remove
del 0
144***[email protected]
Lanyue
col***[email protected]
:
Lanyue
col***[email protected]
Paris
160***[email protected]
Python
Paris
160***[email protected]
jia
jia***[email protected]
Python
jia
jia***[email protected]
593***[email protected]
List Comprehensions
[expression for iter_val in iterable if cond_expr]for
:
:
593***[email protected]