-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_functions.py
More file actions
36 lines (25 loc) · 845 Bytes
/
Copy patharray_functions.py
File metadata and controls
36 lines (25 loc) · 845 Bytes
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
"""
This program demonstrates the use of the arrays in Python.
"""
# array_functions.py
import array
# Create an integer array
int_array = array.array('i', [2, 4, 6, 8, 10])
print(int_array)
# Basic operations on array
# Adding elements
int_array.append(12) # Append an element
print("After appending:", int_array)
# Removing elements
int_array.remove(4) # Remove an element
print("After removing:", int_array)
int_array = array.array('i', [2, 4, 6, 8, 10])
# Remove element at index 2 (removes 6)
int_array.pop(2)
print("After removing element at index 2:", int_array)
int_array = array.array('i', [2, 4, 6, 8, 10])
# Alternatively, we can use `del`
del int_array[1] # Removes element at index 1 (2)
print("After using del to remove element at index 1:", int_array)
# Accessing elements
print("Element at index 1:", int_array[1])