Data Structure Part 1-c

 

#index() :- This function returns the index of the first occurrence of value mentioned in arguments.
#reverse() :- This function reverses the array.
# Python code to demonstrate the working of
# index() and reverse()

# importing "array" for array operations
import array

# initializing array with array values
# initializes array with signed integers
arr = array.array('i', [1, 2, 3, 3, 2, 5])

# printing original array
print("The new created array is : ", end="")
for i in range(0, 6):
print(arr[i], end=" ")

print("\r")
print("The index of 1st occurrence of 3 is : ",arr.index(3))
arr.reverse()
# printing array after reversing
print ("The array after reversing is : ",end="")
for i in range(0,6):
print(arr[i],end=" ")
print("\r")

Comments