-
Notifications
You must be signed in to change notification settings - Fork 0
/
2 class-python.py
195 lines (181 loc) · 4.25 KB
/
2 class-python.py
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
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> ##ARRAY ARRAY ARRAY
>>>
>>> import array
>>> a=array.array('1',[1,2,3,4,5,6])
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
a=array.array('1',[1,2,3,4,5,6])
ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)
>>> a=array.array('int',[1,2,3,4,5,6])
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a=array.array('int',[1,2,3,4,5,6])
TypeError: array() argument 1 must be a unicode character, not str
>>> a=array.array('i',[1,1,2,3,4,5,6])
>>> print(a)
array('i', [1, 1, 2, 3, 4, 5, 6])
>>> import array as arr
>>> a=arr.array('1',[1,2,3,4,5,6])
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
a=arr.array('1',[1,2,3,4,5,6])
ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)
>>> a=arr.array('i',[1,2,3,4,5,6])
>>> print(a)
array('i', [1, 2, 3, 4, 5, 6])
>>>
>>> from array import*
>>> a=array('i',[1,2,3,4,5])
>>> print (a)
array('i', [1, 2, 3, 4, 5])
>>>
>>> #Accessing Array Elements
>>> a[2]
3
>>> print(a[2])
3
>>>
>>> #Lenght of an array
>>> print (len(a))
5
>>>
>>> #Adding Elements to an Array
>>> # append() extend() insert()
>>> print(a)
array('i', [1, 2, 3, 4, 5])
>>>
>>> a.append(8)
>>> print(a)
array('i', [1, 2, 3, 4, 5, 8])
>>>
>>> a.extend[2,4,65]
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
a.extend[2,4,65]
TypeError: 'builtin_function_or_method' object is not subscriptable
>>> a.extend([2,4,65])
>>> print(a)
array('i', [1, 2, 3, 4, 5, 8, 2, 4, 65])
>>>
>>> a.insert(3,100)
>>> print (a)
array('i', [1, 2, 3, 100, 4, 5, 8, 2, 4, 65])
>>> a.insert(1,9,2,99)
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
a.insert(1,9,2,99)
TypeError: insert() takes exactly 2 arguments (4 given)
>>>
>>> #RemovingElementsOfAnArray
>>>
>>> #RemovingElementsOfAnArray
>>> # pop() remove()
>>> # pop(index) remove(number)
>>> print(a)
array('i', [1, 2, 3, 100, 4, 5, 8, 2, 4, 65])
>>> a.pop
<built-in method pop of array.array object at 0x0000000002C49070>
>>> a.pop()
65
>>> print(a)
array('i', [1, 2, 3, 100, 4, 5, 8, 2, 4])
>>> a.pop(3)
100
>>> print(a)
array('i', [1, 2, 3, 4, 5, 8, 2, 4])
>>> a.pop(-2)
2
>>> print(a)
array('i', [1, 2, 3, 4, 5, 8, 4])
>>> a.remove(4)
>>> print(a)
array('i', [1, 2, 3, 5, 8, 4])
>>>
>>> #Array Concatenation (joining of arrays)
>>> b=array.array('i',[1,3,5,6,7,88])
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
b=array.array('i',[1,3,5,6,7,88])
AttributeError: type object 'array.array' has no attribute 'array'
>>> import arrar
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
import arrar
ModuleNotFoundError: No module named 'arrar'
>>> import array
>>> d=array.array('i',[2,3,4,5,6,7])
>>> c=array.array('i',[3,6,7,9])
>>> d=array.array('i')
>>>
>>> b=array.array('i',[2,3,4,5,6,7])
>>> c=array.array('i',[3,6,7,9])
SyntaxError: multiple statements found while compiling a single statement
>>> b=array.array('i',[2,3,4,5,6,7])
>>> c=array.array('i',[3,6,7,9])
>>> e=array.array('i')
>>> e=b+c
>>> print(e)
array('i', [2, 3, 4, 5, 6, 7, 3, 6, 7, 9])
>>>
>>> #SLICING Arrays
>>> print(e)
array('i', [2, 3, 4, 5, 6, 7, 3, 6, 7, 9])
>>> e[0:6]
array('i', [2, 3, 4, 5, 6, 7])
>>> e[0:-3]
array('i', [2, 3, 4, 5, 6, 7, 3])
>>> e[::-1]
array('i', [9, 7, 6, 3, 7, 6, 5, 4, 3, 2])
>>> print(e)
array('i', [2, 3, 4, 5, 6, 7, 3, 6, 7, 9])
>>>
>>> #LOOPING THROUGHT ARRAYS
>>> print(e)
array('i', [2, 3, 4, 5, 6, 7, 3, 6, 7, 9])
>>>
>>> for x in e
SyntaxError: invalid syntax
>>> for x in e;
SyntaxError: invalid syntax
>>> for x in e :
print(x)
2
3
4
5
6
7
3
6
7
9
>>>
>>> for x in e[0:-2] :
print(x)
2
3
4
5
6
7
3
6
>>>
>>> print(e)
array('i', [2, 3, 4, 5, 6, 7, 3, 6, 7, 9])
>>>
>>> jerey=0
>>> while jerey < e[3]:
print(e[jerey])
jerey=jerey+1
2
3
4
5
6
>>>
>>> print (e)
array('i', [2, 3, 4, 5, 6, 7, 3, 6, 7, 9])
>>