|
1 | 1 | #!python3
|
2 | 2 |
|
3 |
| -numlist = [1, 2, 3, 4, 5] |
4 |
| - |
5 |
| ->>> numlist |
6 |
| -[1, 2, 3, 4, 5] |
7 |
| ->>> numlist.reverse() |
8 |
| ->>> numlist |
9 |
| -[5, 4, 3, 2, 1] |
10 |
| - |
11 |
| ->>> numlist.sort() |
12 |
| ->>> numlist |
13 |
| -[1, 2, 3, 4, 5] |
14 |
| - |
15 |
| - |
16 |
| ->>> mystring = "julian" |
17 |
| - |
18 |
| ->>> for i in list(mystring): |
19 |
| - print(i) |
20 |
| - |
21 |
| - |
22 |
| -j |
23 |
| -u |
24 |
| -l |
25 |
| -i |
26 |
| -a |
27 |
| -n |
28 |
| - |
29 |
| - |
30 |
| - |
31 |
| ->>> l = list(mystring) |
32 |
| ->>> t = tuple(mystring) |
33 |
| ->>> |
34 |
| ->>> l |
35 |
| -['j', 'u', 'l', 'i', 'a', 'n'] |
36 |
| ->>> |
37 |
| ->>> t |
38 |
| -('j', 'u', 'l', 'i', 'a', 'n') |
39 |
| - |
40 |
| - |
41 |
| - |
42 |
| ->>> l[0] = "b" |
43 |
| ->>> |
44 |
| ->>> l |
45 |
| -['b', 'u', 'l', 'i', 'a', 'n'] |
46 |
| ->>> |
47 |
| ->>> t[0] = "m" |
48 |
| -Traceback (most recent call last): |
49 |
| - File "<pyshell#59>", line 1, in <module> |
50 |
| - t[0] = "m" |
51 |
| -TypeError: 'tuple' object does not support item assignment |
52 |
| ->>> |
53 |
| - |
54 |
| - |
55 |
| - |
56 |
| - |
57 |
| ->>> l.pop() |
58 |
| -'n' |
59 |
| ->>> l |
60 |
| -['b', 'u', 'l', 'i', 'a'] |
61 |
| ->>> |
62 |
| - |
63 |
| - |
64 |
| ->>> l.insert(5, "n") |
65 |
| ->>> |
66 |
| ->>> l |
67 |
| -['b', 'u', 'l', 'i', 'a', 'n'] |
68 |
| ->>> |
69 |
| ->>> |
70 |
| - |
71 |
| - |
72 |
| - |
73 |
| - |
74 |
| ->>> l.pop(0) |
75 |
| -'b' |
76 |
| ->>> |
77 |
| ->>> l |
78 |
| -['u', 'l', 'i', 'a', 'n'] |
79 |
| ->>> |
80 |
| - |
81 |
| - |
82 |
| - |
83 |
| ->>> l.insert(0, "m") |
84 |
| ->>> |
85 |
| ->>> l |
86 |
| -['m', 'u', 'l', 'i', 'a', 'n'] |
87 |
| ->>> |
88 |
| - |
89 |
| - |
90 |
| - |
91 |
| ->>> del l[0] |
92 |
| ->>> |
93 |
| ->>> l |
94 |
| -['u', 'l', 'i', 'a', 'n'] |
95 |
| ->>> |
96 |
| ->>> |
97 |
| - |
98 |
| - |
99 |
| - |
100 |
| - |
101 |
| - |
102 |
| -DICTS: |
103 |
| - |
104 |
| ->>> pybites = {'julian': 30, 'bob': 33, 'mike': 33} |
105 |
| ->>> |
106 |
| ->>> pybites |
107 |
| -{'julian': 30, 'bob': 33, 'mike': 33} |
108 |
| ->>> |
109 |
| - |
110 |
| - |
111 |
| ->>> people = {} |
112 |
| ->>> people['julian'] = 30 |
113 |
| ->>> people |
114 |
| -{'julian': 30} |
115 |
| - |
116 |
| ->>> people['bob'] = 43 |
117 |
| ->>> people |
118 |
| -{'julian': 30, 'bob': 43} |
119 |
| ->>> |
120 |
| - |
121 |
| - |
122 |
| ->>> pybites.keys() |
123 |
| -dict_keys(['julian', 'bob', 'mike']) |
124 |
| ->>> |
125 |
| - |
126 |
| ->>> pybites.values() |
127 |
| -dict_values([30, 33, 33]) |
128 |
| - |
129 |
| ->>> pybites.items() |
130 |
| -dict_items([('julian', 30), ('bob', 33), ('mike', 33)]) |
131 |
| ->>> |
132 |
| - |
133 |
| ->>> for keys in pybites.keys(): |
134 |
| - print(keys) |
135 |
| - |
136 |
| - |
137 |
| -julian |
138 |
| -bob |
139 |
| -mike |
140 |
| ->>> |
141 |
| - |
142 |
| ->>> for values in pybites.values(): |
143 |
| - print(values) |
144 |
| - |
145 |
| - |
146 |
| -30 |
147 |
| -33 |
148 |
| -33 |
149 |
| ->>> |
150 |
| - |
151 |
| ->>> for keys, values in pybites.items(): |
152 |
| - print(keys + str(values)) |
153 |
| - |
154 |
| - |
155 |
| -julian30 |
156 |
| -bob33 |
157 |
| -mike33 |
158 |
| ->>> |
159 |
| - |
160 |
| ->>> for keys, values in pybites.items(): |
161 |
| - print('%s is %d years of age' % (keys, values)) |
162 |
| - |
163 |
| - |
164 |
| -julian is 30 years of age |
165 |
| -bob is 33 years of age |
166 |
| -mike is 33 years of age |
167 |
| ->>> |
| 3 | +# numlist = [1, 2, 3, 4, 5] |
| 4 | +# |
| 5 | +# >>> numlist |
| 6 | +# [1, 2, 3, 4, 5] |
| 7 | +# >>> numlist.reverse() |
| 8 | +# >>> numlist |
| 9 | +# [5, 4, 3, 2, 1] |
| 10 | +# |
| 11 | +# >>> numlist.sort() |
| 12 | +# >>> numlist |
| 13 | +# [1, 2, 3, 4, 5] |
| 14 | +# |
| 15 | +# |
| 16 | +# >>> mystring = "julian" |
| 17 | +# |
| 18 | +# >>> for i in list(mystring): |
| 19 | +# print(i) |
| 20 | +# |
| 21 | +# |
| 22 | +# j |
| 23 | +# u |
| 24 | +# l |
| 25 | +# i |
| 26 | +# a |
| 27 | +# n |
| 28 | +# |
| 29 | +# |
| 30 | +# |
| 31 | +# >>> l = list(mystring) |
| 32 | +# >>> t = tuple(mystring) |
| 33 | +# >>> |
| 34 | +# >>> l |
| 35 | +# ['j', 'u', 'l', 'i', 'a', 'n'] |
| 36 | +# >>> |
| 37 | +# >>> t |
| 38 | +# ('j', 'u', 'l', 'i', 'a', 'n') |
| 39 | +# |
| 40 | +# |
| 41 | +# |
| 42 | +# >>> l[0] = "b" |
| 43 | +# >>> |
| 44 | +# >>> l |
| 45 | +# ['b', 'u', 'l', 'i', 'a', 'n'] |
| 46 | +# >>> |
| 47 | +# >>> t[0] = "m" |
| 48 | +# Traceback (most recent call last): |
| 49 | +# File "<pyshell#59>", line 1, in <module> |
| 50 | +# t[0] = "m" |
| 51 | +# TypeError: 'tuple' object does not support item assignment |
| 52 | +# >>> |
| 53 | +# |
| 54 | +# |
| 55 | +# |
| 56 | +# |
| 57 | +# >>> l.pop() |
| 58 | +# 'n' |
| 59 | +# >>> l |
| 60 | +# ['b', 'u', 'l', 'i', 'a'] |
| 61 | +# >>> |
| 62 | +# |
| 63 | +# |
| 64 | +# >>> l.insert(5, "n") |
| 65 | +# >>> |
| 66 | +# >>> l |
| 67 | +# ['b', 'u', 'l', 'i', 'a', 'n'] |
| 68 | +# >>> |
| 69 | +# >>> |
| 70 | +# |
| 71 | +# |
| 72 | +# |
| 73 | +# |
| 74 | +# >>> l.pop(0) |
| 75 | +# 'b' |
| 76 | +# >>> |
| 77 | +# >>> l |
| 78 | +# ['u', 'l', 'i', 'a', 'n'] |
| 79 | +# >>> |
| 80 | +# |
| 81 | +# |
| 82 | +# |
| 83 | +# >>> l.insert(0, "m") |
| 84 | +# >>> |
| 85 | +# >>> l |
| 86 | +# ['m', 'u', 'l', 'i', 'a', 'n'] |
| 87 | +# >>> |
| 88 | +# |
| 89 | +# |
| 90 | +# |
| 91 | +# >>> del l[0] |
| 92 | +# >>> |
| 93 | +# >>> l |
| 94 | +# ['u', 'l', 'i', 'a', 'n'] |
| 95 | +# >>> |
| 96 | +# >>> |
| 97 | +# |
| 98 | +# |
| 99 | +# |
| 100 | +# |
| 101 | +# |
| 102 | +# DICTS: |
| 103 | +# |
| 104 | +# >>> pybites = {'julian': 30, 'bob': 33, 'mike': 33} |
| 105 | +# >>> |
| 106 | +# >>> pybites |
| 107 | +# {'julian': 30, 'bob': 33, 'mike': 33} |
| 108 | +# >>> |
| 109 | +# |
| 110 | +# |
| 111 | +# >>> people = {} |
| 112 | +# >>> people['julian'] = 30 |
| 113 | +# >>> people |
| 114 | +# {'julian': 30} |
| 115 | +# |
| 116 | +# >>> people['bob'] = 43 |
| 117 | +# >>> people |
| 118 | +# {'julian': 30, 'bob': 43} |
| 119 | +# >>> |
| 120 | +# |
| 121 | +# |
| 122 | +# >>> pybites.keys() |
| 123 | +# dict_keys(['julian', 'bob', 'mike']) |
| 124 | +# >>> |
| 125 | +# |
| 126 | +# >>> pybites.values() |
| 127 | +# dict_values([30, 33, 33]) |
| 128 | +# |
| 129 | +# >>> pybites.items() |
| 130 | +# dict_items([('julian', 30), ('bob', 33), ('mike', 33)]) |
| 131 | +# >>> |
| 132 | +# |
| 133 | +# >>> for keys in pybites.keys(): |
| 134 | +# print(keys) |
| 135 | +# |
| 136 | +# |
| 137 | +# julian |
| 138 | +# bob |
| 139 | +# mike |
| 140 | +# >>> |
| 141 | +# |
| 142 | +# >>> for values in pybites.values(): |
| 143 | +# print(values) |
| 144 | +# |
| 145 | +# |
| 146 | +# 30 |
| 147 | +# 33 |
| 148 | +# 33 |
| 149 | +# >>> |
| 150 | +# |
| 151 | +# >>> for keys, values in pybites.items(): |
| 152 | +# print(keys + str(values)) |
| 153 | +# |
| 154 | +# |
| 155 | +# julian30 |
| 156 | +# bob33 |
| 157 | +# mike33 |
| 158 | +# >>> |
| 159 | +# |
| 160 | +# >>> for keys, values in pybites.items(): |
| 161 | +# print('%s is %d years of age' % (keys, values)) |
| 162 | +# |
| 163 | +# |
| 164 | +# julian is 30 years of age |
| 165 | +# bob is 33 years of age |
| 166 | +# mike is 33 years of age |
| 167 | +# >>> |
0 commit comments