列表
- lists=['a','b','c']
- lists=['a',1,44,'aa']
- print(lists)
- print(lists[0])
- print(lists[-1])
- print(lists[-2])
- lists.append('a')
- index=0
- lists.insert(index,'value')
- del lists[index]
- lists.pop()
- lists.pop(index)
- popped_object=lists.pop()
- value='a'
- lists.remove(value)
- '''just remove the first object whose value is 'a'. If there are more than one object whose value is 'a' '''
- '''we have to call remove() several times
- lists.sort()
- lists.sort(reverse=True)
- sorted(lists)
- lists.reverse()
- len(lists)
- for obj in lists:
- print(obj)
- ''' use range() function to generate a series of number '''
- for value in range(1,5)
- print(value)
- numbers=list(range(1,6))
- numbers=list(range(2,11,2)) ''' range(start,end,step) '''
- square=value**2 '''assign value to the power two to variable square '''
- min(numbers)
- max(numbers)
- sum(numbers)
- squares=[value**2 for value in range(1,11)]
- ''' list comprehension '''
- ''' listName = [ expression for-loop] '''
- ''' [0, 3) . Slice'''
- print(squares[0:3])
- print(squares[:3])
- print(squares[0:])
- print(squares[-2:])
- for s in squares[0:3]:
- print(s)
- ''' ------ '''
- A=['a','b']
- B=A[:]
- A.append('c')
- B.append('d')
- print(A)
- print(B)
- ''' ['a','b','c']
- ['a','b','d'] '''
- ''' ------ '''
- ''' ------ '''
- A=['a','b']
- B=A
- A.append('c')
- B.append('d')
- print(A)
- print(B)
- ''' ['a','b','c','d']
- ['a','b','c','d'] '''
- ''' ------ '''