0% found this document useful (0 votes)
19 views1 page

Python Array Operations and Examples

The document contains Python code snippets demonstrating the use of arrays, including creation, appending, reversing, and inserting elements. It also includes functions to calculate the length of arrays and identify missing numbers in a specified range. Overall, it showcases basic array operations and manipulations in Python.

Uploaded by

MD COMPUTERS
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Python Array Operations and Examples

The document contains Python code snippets demonstrating the use of arrays, including creation, appending, reversing, and inserting elements. It also includes functions to calculate the length of arrays and identify missing numbers in a specified range. Overall, it showcases basic array operations and manipulations in Python.

Uploaded by

MD COMPUTERS
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

from array import * ………………………………………………………

array_num = array('i', [1,3,5,7,9]) from array import array

for i in array_num: my_array = array('i', [10, 20, 30, 40, 50, 60])

print(i) for i in my_array:

print("Access first three items individually") print(i)

print(array_num[0]) ……………………………………………

print(array_num[1]) from array import array

print(array_num[2]) num_array = array('i', [10,20,30,40,50])

………………............................................ print("Length of the array is:")

from array import * print(len(num_array))

array_num = array('i', [1, 3, 5, 7, 9]) ………………………………………………………………

print("Original array: "+str(array_num)) from array import array

print("Append 11 at the end of the array:") a = array("I", (12,25))

array_num.append(11) print([Link])

print("New array: "+str(array_num)) a = array("f", (12.236,36.36))

……………………………………………………………… print([Link])

from array import * …………………………………………

array_num = array('i', [1, 3, 5, 3, 7, 1, 9, 3]) import array as arr

print("Original array: "+str(array_num)) def test(nums):

array_num.reverse() return sum(range(10, 21)) - sum(list(nums))

print("Reverse the order of the items:")

print(str(array_num)) array_num = [Link]('i', [10, 11, 12, 13, 14, 16, 17, 18, 19,
20])
………………………………………………………….
print("Original array:")
from array import *
for i in range(len(array_num)):
array_num = array('i', [1, 3, 5, 7, 9])
print(array_num[i], end=' ')
print("Original array: "+str(array_num))
print("\nMissing number in the said array (10-20):
print("Length in bytes of one array item:
",test(array_num))
"+str(array_num.itemsize))

………………………………………………………………
array_num = [Link]('i', [10, 11, 12, 13, 14, 15, 16, 17, 18,
from array import *
19])
array_num = array('i', [1, 3, 5, 7, 9])
print("\nOriginal array:")
print("Original array: "+str(array_num))
for i in range(len(array_num)):
print("Insert new value 4 before 3:")
print(array_num[i], end=' ')
array_num.insert(1, 4)
print("\nMissing number in the said array (10-20):
print("New array: "+str(array_num)) ",test(array_num))

You might also like