YUANya

导航

 
  1 fruit = ['apple','banana','peach']
  2 print fruit[0],fruit[-1]
  3 
  4 fruit_1 =[]
  5 fruit_1.append('orange')
  6 print fruit_1
  7 
  8 fruit.insert(1,'orange')
  9 del fruit[2]
 10 print fruit
 11 
 12 '''
 13 apple peach
 14 ['orange']
 15 ['apple', 'orange', 'peach']
 16 '''
 17 
 18 pop_1 = fruit.pop(1)
 19 print pop_1,"\n",fruit
 20 
 21 '''
 22 orange
 23 ['apple', 'peach']
 24 '''
 25 
 26 apple = 'apple'
 27 fruit.remove(apple)
 28 print fruit,"\n",fruit_1
 29 
 30 '''
 31 ['peach']
 32 ['orange']
 33 '''
 34 
 35 fruit_2 = ['a','b','c','d','e','f']
 36 fruit = fruit_1 + fruit_2
 37 print fruit
 38 
 39 '''
 40 ['orange', 'a', 'b', 'c', 'd', 'e', 'f']
 41 '''
 42 new_fruit = sorted(fruit,reverse=True)
 43 print fruit,"\n",new_fruit
 44 new_fruit.sort(reverse=True)
 45 print new_fruit
 46 new_fruit.reverse()
 47 print new_fruit
 48 
 49 '''
 50 ['orange', 'a', 'b', 'c', 'd', 'e', 'f']
 51 ['orange', 'f', 'e', 'd', 'c', 'b', 'a']
 52 ['orange', 'f', 'e', 'd', 'c', 'b', 'a']
 53 ['a', 'b', 'c', 'd', 'e', 'f', 'orange']
 54 
 55 '''
 56 
 57 length = len(new_fruit)
 58 print length
 59 
 60 #7
 61 
 62 #empty = []
 63 #iprint empty[-1]
 64 
 65 '''
 66 Traceback (most recent call last):
 67       File "t.py", line 61, in <module>
 68           print empty[-1]
 69           IndexError: list index out of range
 70 '''
 71 
 72 for i in new_fruit:
 73     print i
 74 print i
 75 
 76 '''
 77 a
 78 b
 79 c
 80 d
 81 e
 82 f
 83 orange
 84 orange
 85 '''
 86 
 87 new_list = list(range(1,15,3))
 88 print new_list
 89 
 90 #[1, 4, 7, 10, 13]
 91 
 92 max_in_list = max(new_list)
 93 min_in_list = min(new_list)
 94 sum_in_list = sum(new_list)
 95 print max_in_list,"\n",min_in_list,"\n",sum_in_list
 96 
 97 '''
 98 13
 99 1
100 35
101 '''
102 double=[i**2 for i in range(1,20)]
103 new_double = double[:]
104 print new_double
105 print double[4:]
106 
107 #[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361]
108 #[25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361]
109 
110 for single in double[5:-1]:
111     print single
112 
113 '''
114 36
115 49
116 64
117 81
118 100
119 121
120 144
121 169
122 196
123 225
124 256
125 289
126 324
127 '''
128 new_double_2 = double
129 double.pop(0)
130 print double
131 print new_double_2
132 print new_double
133 
134 '''
135 [4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361]
136 [4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361]
137 [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361]
138 '''
139 
140 new_double[1] =2500000000000
141 print new_double
142 
143 #[1, 2500000000000, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361]
144 
145 scale = [1,8]
146 for number in scale:
147     print number
148 
149 
150 scale = (1,8)
151 for number in scale:
152     print number
153 
154 '''
155 1
156 8
157 1
158 8
159 '''

问题:列表可以用[ ]or( )???

 1 scale = [1,8]
 2 for number in scale:
 3     print number
 4 
 5 
 6 scale = (1,8)
 7 for number in scale:
 8     print number
 9 
10 '''
11 1
12 8
13 1
14 8
15 '''
posted on 2019-07-03 20:46  YUANya  阅读(236)  评论(0编辑  收藏  举报